diff --git a/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql
new file mode 100644
index 0000000000..6b3481a6bb
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql
@@ -0,0 +1,17724 @@
+
+-- 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.
+
+BEGIN
+ DECLARE
+ @claimId AS INT,
+ @claimName AS nvarchar(max),
+ @parentResourceClaimId AS INT,
+ @existingParentResourceClaimId AS INT,
+ @claimSetId AS INT,
+ @claimSetName AS nvarchar(max),
+ @authorizationStrategyId AS INT,
+ @msg AS nvarchar(max),
+ @createActionId AS INT,
+ @readActionId AS INT,
+ @updateActionId AS INT,
+ @deleteActionId AS INT,
+ @readChangesActionId AS INT,
+ @resourceClaimActionId AS INT,
+ @claimSetResourceClaimActionId AS INT
+
+ DECLARE @claimIdStack AS TABLE (Id INT IDENTITY, ResourceClaimId INT)
+
+ SELECT @createActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Create';
+
+ SELECT @readActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Read';
+
+ SELECT @updateActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Update';
+
+ SELECT @deleteActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Delete';
+
+ SELECT @readChangesActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'ReadChanges';
+
+ BEGIN TRANSACTION
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of root
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('edFiTypes', 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolYearType', 'http://ed-fi.org/ods/identity/claims/schoolYearType', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('systemDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('absenceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicHonorCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicSubjectDescriptor', 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('achievementCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('additionalCreditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('addressTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrationEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrativeFundingControlDescriptor', 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ancestryEthnicOriginDescriptor', 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemResultDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assignmentLateStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attemptStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attendanceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('barrierToInternetAccessInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('behaviorDescriptor', 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarEventDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('careerPathwayDescriptor', 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterApprovalAgencyTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('citizenshipStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classroomPositionDescriptor', 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortYearTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contactTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contentClassDescriptor', 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('continuationOfServicesReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('costRateDescriptor', 'http://ed-fi.org/ods/identity/claims/costRateDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('countryDescriptor', 'http://ed-fi.org/ods/identity/claims/countryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseAttemptResultDescriptor', 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseDefinedByDescriptor', 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseGPAApplicabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseLevelCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseRepeatCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialFieldDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cteProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('curriculumUsedDescriptor', 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('deliveryMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diagnosisDescriptor', 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDeterminationSourceTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineActionLengthDifferenceReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncidentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationalEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationAssociationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationPlanDescriptor', 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('electronicMailTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('employmentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryGradeLevelReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eventCircumstanceDescriptor', 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('exitWithdrawTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('financialCollectionDescriptor', 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradePointAverageTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlanTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gunFreeSchoolsActReportingStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessPrimaryNighttimeResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identificationDocumentUseDescriptor', 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('incidentLocationDescriptor', 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorGroupDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('institutionTelephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interactivityStyleDescriptor', 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessTypeInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetPerformanceInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionClassDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionEffectivenessRatingDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageDescriptor', 'http://ed-fi.org/ods/identity/claims/languageDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageInstructionProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageUseDescriptor', 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceStrengthDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('levelOfEducationDescriptor', 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('limitedEnglishProficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localeDescriptor', 'http://ed-fi.org/ods/identity/claims/localeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgencyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('magnetSpecialProgramEmphasisSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('mediumOfInstructionDescriptor', 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('methodCreditEarnedDescriptor', 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('migrantEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('modelEntityDescriptor', 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('monitoredDescriptor', 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('networkPurposeDescriptor', 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('oldEthnicityDescriptor', 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('otherNameTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationDescriptor', 'http://ed-fi.org/ods/identity/claims/participationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceBaseConversionDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('personalInformationVerificationDescriptor', 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('platformTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('populationServedDescriptor', 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postingResultDescriptor', 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitutionLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAwayFromSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceProviderDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('proficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programAssignmentDescriptor', 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programSponsorDescriptor', 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressDescriptor', 'http://ed-fi.org/ods/identity/claims/progressDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerProfitabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('publicationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('questionFormDescriptor', 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('raceDescriptor', 'http://ed-fi.org/ods/identity/claims/raceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonExitedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonNotTestedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('recognitionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationDescriptor', 'http://ed-fi.org/ods/identity/claims/relationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('repeatIdentifierDescriptor', 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reporterDescriptionDescriptor', 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportingTagDescriptor', 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('residencyStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responseIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responsibilityDescriptor', 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEventReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('resultDatatypeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('retestIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceImplementStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolFoodServiceProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationDescriptor', 'http://ed-fi.org/ods/identity/claims/separationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('serviceDescriptor', 'http://ed-fi.org/ods/identity/claims/serviceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sexDescriptor', 'http://ed-fi.org/ods/identity/claims/sexDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationSettingDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffClassificationDescriptor', 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeaveEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateAbbreviationDescriptor', 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('submissionStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('technicalSkillsAssessmentDescriptor', 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('telephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('termDescriptor', 'http://ed-fi.org/ods/identity/claims/termDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAParticipantDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartASchoolDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('tribalAffiliationDescriptor', 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('visaDescriptor', 'http://ed-fi.org/ods/identity/claims/visaDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('weaponDescriptor', 'http://ed-fi.org/ods/identity/claims/weaponDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('managedDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accommodationDescriptor', 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentReportingMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizations', 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityOrganization', 'http://ed-fi.org/ods/identity/claims/communityOrganization', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityOrganization
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProvider', 'http://ed-fi.org/ods/identity/claims/communityProvider', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityProvider
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetwork', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationServiceCenter', 'http://ed-fi.org/ods/identity/claims/educationServiceCenter', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationServiceCenter
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgency', 'http://ed-fi.org/ods/identity/claims/localEducationAgency', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/localEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('organizationDepartment', 'http://ed-fi.org/ods/identity/claims/organizationDepartment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/organizationDepartment
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitution', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/postSecondaryInstitution
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/school'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/school'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('school', 'http://ed-fi.org/ods/identity/claims/school', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/school
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateEducationAgency', 'http://ed-fi.org/ods/identity/claims/stateEducationAgency', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/stateEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/people'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/people'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('people', 'http://ed-fi.org/ods/identity/claims/domains/people', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/parent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/parent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('parent', 'http://ed-fi.org/ods/identity/claims/parent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staff'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staff'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staff', 'http://ed-fi.org/ods/identity/claims/staff', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staff
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/student'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/student'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('student', 'http://ed-fi.org/ods/identity/claims/student', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/student
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicWeek', 'http://ed-fi.org/ods/identity/claims/academicWeek', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountabilityRating', 'http://ed-fi.org/ods/identity/claims/accountabilityRating', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/accountabilityRating
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('balanceSheetDimension', 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('bellSchedule', 'http://ed-fi.org/ods/identity/claims/bellSchedule', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendar'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendar'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendar', 'http://ed-fi.org/ods/identity/claims/calendar', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarDate', 'http://ed-fi.org/ods/identity/claims/calendarDate', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classPeriod', 'http://ed-fi.org/ods/identity/claims/classPeriod', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/classPeriod
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohort'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohort'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohort', 'http://ed-fi.org/ods/identity/claims/cohort', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProviderLicense', 'http://ed-fi.org/ods/identity/claims/communityProviderLicense', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityProviderLicense
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyObjective', 'http://ed-fi.org/ods/identity/claims/competencyObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/course'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/course'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('course', 'http://ed-fi.org/ods/identity/claims/course', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/course
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseOffering', 'http://ed-fi.org/ods/identity/claims/courseOffering', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/courseOffering
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseTranscript', 'http://ed-fi.org/ods/identity/claims/courseTranscript', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('descriptorMapping', 'http://ed-fi.org/ods/identity/claims/descriptorMapping', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineAction', 'http://ed-fi.org/ods/identity/claims/disciplineAction', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncident', 'http://ed-fi.org/ods/identity/claims/disciplineIncident', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationInterventionPrescriptionAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetworkAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationPeerAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('feederSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/feederSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('functionDimension', 'http://ed-fi.org/ods/identity/claims/functionDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('fundDimension', 'http://ed-fi.org/ods/identity/claims/fundDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/grade'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/grade'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('grade', 'http://ed-fi.org/ods/identity/claims/grade', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntry', 'http://ed-fi.org/ods/identity/claims/gradebookEntry', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriod', 'http://ed-fi.org/ods/identity/claims/gradingPeriod', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlan', 'http://ed-fi.org/ods/identity/claims/graduationPlan', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/intervention'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/intervention'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('intervention', 'http://ed-fi.org/ods/identity/claims/intervention', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionPrescription', 'http://ed-fi.org/ods/identity/claims/interventionPrescription', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionStudy', 'http://ed-fi.org/ods/identity/claims/interventionStudy', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/location'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/location'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('location', 'http://ed-fi.org/ods/identity/claims/location', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/location
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectDimension', 'http://ed-fi.org/ods/identity/claims/objectDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('openStaffPosition', 'http://ed-fi.org/ods/identity/claims/openStaffPosition', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalUnitDimension', 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/person'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/person'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('person', 'http://ed-fi.org/ods/identity/claims/person', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEvent', 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/program'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/program'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('program', 'http://ed-fi.org/ods/identity/claims/program', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/program
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programDimension', 'http://ed-fi.org/ods/identity/claims/programDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('projectDimension', 'http://ed-fi.org/ods/identity/claims/projectDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportCard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reportCard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportCard', 'http://ed-fi.org/ods/identity/claims/reportCard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEvent', 'http://ed-fi.org/ods/identity/claims/restraintEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/section'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/section'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('section', 'http://ed-fi.org/ods/identity/claims/section', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/section
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionAttendanceTakenEvent', 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/session'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/session'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('session', 'http://ed-fi.org/ods/identity/claims/session', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/session
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceDimension', 'http://ed-fi.org/ods/identity/claims/sourceDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffAbsenceEvent', 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffCohortAssociation', 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationContactAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeave', 'http://ed-fi.org/ods/identity/claims/staffLeave', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffProgramAssociation', 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSectionAssociation', 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staffSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAcademicRecord', 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessmentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCohortAssociation', 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCompetencyObjective', 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCTEProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentBehaviorAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentNonOffenderAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationResponsibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentGradebookEntry', 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentHomelessProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAssociation', 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLanguageInstructionProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLearningObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentLearningObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLearningObjective', 'http://ed-fi.org/ods/identity/claims/studentLearningObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentMigrantEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentNeglectedOrDelinquentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentParentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParentAssociation', 'http://ed-fi.org/ods/identity/claims/studentParentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithStudentsOnly'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithStudentsOnly''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithStudentsOnly'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolFoodServiceProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAssociation', 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/studentSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTitleIPartAProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCourseAssociation', 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyProgramAssociation', 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentMetadata', 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessment', 'http://ed-fi.org/ods/identity/claims/assessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItem', 'http://ed-fi.org/ods/identity/claims/assessmentItem', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentScoreRangeLearningStandard', 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectiveAssessment', 'http://ed-fi.org/ods/identity/claims/objectiveAssessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessment', 'http://ed-fi.org/ods/identity/claims/studentAssessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/services/identity'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/services/identity'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identity', 'http://ed-fi.org/ods/identity/claims/services/identity', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/services/identity
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationStandards', 'http://ed-fi.org/ods/identity/claims/domains/educationStandards', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credential'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credential'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credential', 'http://ed-fi.org/ods/identity/claims/credential', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningObjective', 'http://ed-fi.org/ods/identity/claims/learningObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/learningObjective
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandard', 'http://ed-fi.org/ods/identity/claims/learningStandard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/learningStandard
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceAssociation', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryRelationships', 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsOnly''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsOnly'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationAssignmentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationEmploymentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/studentSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyDomain', 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/survey'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/survey'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('survey', 'http://ed-fi.org/ods/identity/claims/survey', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestion', 'http://ed-fi.org/ods/identity/claims/surveyQuestion', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestionResponse', 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponse', 'http://ed-fi.org/ods/identity/claims/surveyResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySection'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySection'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySection', 'http://ed-fi.org/ods/identity/claims/surveySection', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponse', 'http://ed-fi.org/ods/identity/claims/surveySectionResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationContent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationContent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationContent', 'http://ed-fi.org/ods/identity/claims/educationContent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationContent
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+
+ COMMIT TRANSACTION
+END
diff --git a/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml
new file mode 100644
index 0000000000..0dd2c3cac1
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml
@@ -0,0 +1,1420 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql
new file mode 100644
index 0000000000..5ea27eaf2e
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql
@@ -0,0 +1,15836 @@
+
+-- 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.
+
+DO $$
+DECLARE
+ claim_id INTEGER;
+ claim_name VARCHAR(2048);
+ parent_resource_claim_id INTEGER;
+ existing_parent_resource_claim_id INTEGER;
+ claim_set_id INTEGER;
+ claim_set_name VARCHAR(255);
+ authorization_strategy_id INTEGER;
+ create_action_id INTEGER;
+ read_action_id INTEGER;
+ update_action_id INTEGER;
+ delete_action_id INTEGER;
+ readchanges_action_id INTEGER;
+ resource_claim_action_id INTEGER;
+ claim_set_resource_claim_action_id INTEGER;
+ claim_id_stack INTEGER ARRAY;
+BEGIN
+ SELECT actionid INTO create_action_id
+ FROM dbo.actions WHERE ActionName = 'Create';
+
+ SELECT actionid INTO read_action_id
+ FROM dbo.actions WHERE ActionName = 'Read';
+
+ SELECT actionid INTO update_action_id
+ FROM dbo.actions WHERE ActionName = 'Update';
+
+ SELECT actionid INTO delete_action_id
+ FROM dbo.actions WHERE ActionName = 'Delete';
+
+ SELECT actionid INTO readchanges_action_id
+ FROM dbo.actions WHERE ActionName = 'ReadChanges';
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of root
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('edFiTypes', 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolYearType';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolYearType', 'http://ed-fi.org/ods/identity/claims/schoolYearType', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('systemDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('absenceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicHonorCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicSubjectDescriptor', 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('achievementCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('additionalCreditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('addressTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrationEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrativeFundingControlDescriptor', 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ancestryEthnicOriginDescriptor', 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemResultDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assignmentLateStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attemptStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attendanceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('barrierToInternetAccessInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('behaviorDescriptor', 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarEventDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('careerPathwayDescriptor', 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterApprovalAgencyTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('citizenshipStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classroomPositionDescriptor', 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortYearTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contactTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contentClassDescriptor', 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('continuationOfServicesReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/costRateDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('costRateDescriptor', 'http://ed-fi.org/ods/identity/claims/costRateDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/countryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('countryDescriptor', 'http://ed-fi.org/ods/identity/claims/countryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseAttemptResultDescriptor', 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseDefinedByDescriptor', 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseGPAApplicabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseLevelCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseRepeatCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialFieldDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cteProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('curriculumUsedDescriptor', 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('deliveryMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diagnosisDescriptor', 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDeterminationSourceTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineActionLengthDifferenceReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncidentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationalEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationAssociationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationPlanDescriptor', 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('electronicMailTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('employmentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryGradeLevelReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eventCircumstanceDescriptor', 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('exitWithdrawTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('financialCollectionDescriptor', 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradePointAverageTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlanTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gunFreeSchoolsActReportingStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessPrimaryNighttimeResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identificationDocumentUseDescriptor', 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('incidentLocationDescriptor', 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorGroupDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('institutionTelephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interactivityStyleDescriptor', 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessTypeInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetPerformanceInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionClassDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionEffectivenessRatingDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageDescriptor', 'http://ed-fi.org/ods/identity/claims/languageDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageInstructionProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageUseDescriptor', 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceStrengthDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('levelOfEducationDescriptor', 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('limitedEnglishProficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localeDescriptor', 'http://ed-fi.org/ods/identity/claims/localeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgencyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('magnetSpecialProgramEmphasisSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('mediumOfInstructionDescriptor', 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('methodCreditEarnedDescriptor', 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('migrantEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('modelEntityDescriptor', 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('monitoredDescriptor', 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('networkPurposeDescriptor', 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('oldEthnicityDescriptor', 'http://ed-fi.org/ods/identity/claims/oldEthnicityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('otherNameTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/participationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationDescriptor', 'http://ed-fi.org/ods/identity/claims/participationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceBaseConversionDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('personalInformationVerificationDescriptor', 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('platformTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('populationServedDescriptor', 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postingResultDescriptor', 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitutionLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAwayFromSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceProviderDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('proficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programAssignmentDescriptor', 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programSponsorDescriptor', 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/progressDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressDescriptor', 'http://ed-fi.org/ods/identity/claims/progressDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerProfitabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('publicationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('questionFormDescriptor', 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/raceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('raceDescriptor', 'http://ed-fi.org/ods/identity/claims/raceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonExitedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonNotTestedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('recognitionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/relationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationDescriptor', 'http://ed-fi.org/ods/identity/claims/relationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('repeatIdentifierDescriptor', 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reporterDescriptionDescriptor', 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportingTagDescriptor', 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('residencyStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responseIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responsibilityDescriptor', 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEventReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('resultDatatypeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('retestIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceImplementStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolFoodServiceProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/separationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationDescriptor', 'http://ed-fi.org/ods/identity/claims/separationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/serviceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('serviceDescriptor', 'http://ed-fi.org/ods/identity/claims/serviceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sexDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sexDescriptor', 'http://ed-fi.org/ods/identity/claims/sexDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationSettingDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffClassificationDescriptor', 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeaveEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateAbbreviationDescriptor', 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('submissionStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('technicalSkillsAssessmentDescriptor', 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('telephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/termDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('termDescriptor', 'http://ed-fi.org/ods/identity/claims/termDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAParticipantDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartASchoolDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('tribalAffiliationDescriptor', 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/visaDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('visaDescriptor', 'http://ed-fi.org/ods/identity/claims/visaDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/weaponDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('weaponDescriptor', 'http://ed-fi.org/ods/identity/claims/weaponDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('managedDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accommodationDescriptor', 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentReportingMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizations', 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityOrganization';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityOrganization', 'http://ed-fi.org/ods/identity/claims/communityOrganization', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityOrganization
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityProvider';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProvider', 'http://ed-fi.org/ods/identity/claims/communityProvider', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityProvider
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetwork', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationServiceCenter';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationServiceCenter', 'http://ed-fi.org/ods/identity/claims/educationServiceCenter', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationServiceCenter
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localEducationAgency';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgency', 'http://ed-fi.org/ods/identity/claims/localEducationAgency', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/localEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/organizationDepartment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('organizationDepartment', 'http://ed-fi.org/ods/identity/claims/organizationDepartment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/organizationDepartment
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitution', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/postSecondaryInstitution
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/school'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/school';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('school', 'http://ed-fi.org/ods/identity/claims/school', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/school
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/stateEducationAgency';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateEducationAgency', 'http://ed-fi.org/ods/identity/claims/stateEducationAgency', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/stateEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/people'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/people';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('people', 'http://ed-fi.org/ods/identity/claims/domains/people', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/parent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/parent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('parent', 'http://ed-fi.org/ods/identity/claims/parent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staff'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staff';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staff', 'http://ed-fi.org/ods/identity/claims/staff', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staff
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/student'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/student';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('student', 'http://ed-fi.org/ods/identity/claims/student', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/student
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicWeek';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicWeek', 'http://ed-fi.org/ods/identity/claims/academicWeek', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accountabilityRating';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountabilityRating', 'http://ed-fi.org/ods/identity/claims/accountabilityRating', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/accountabilityRating
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('balanceSheetDimension', 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/bellSchedule';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('bellSchedule', 'http://ed-fi.org/ods/identity/claims/bellSchedule', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendar'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendar';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendar', 'http://ed-fi.org/ods/identity/claims/calendar', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarDate';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarDate', 'http://ed-fi.org/ods/identity/claims/calendarDate', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/classPeriod';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classPeriod', 'http://ed-fi.org/ods/identity/claims/classPeriod', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/classPeriod
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohort'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohort';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohort', 'http://ed-fi.org/ods/identity/claims/cohort', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityProviderLicense';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProviderLicense', 'http://ed-fi.org/ods/identity/claims/communityProviderLicense', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityProviderLicense
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/competencyObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyObjective', 'http://ed-fi.org/ods/identity/claims/competencyObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/course'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/course';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('course', 'http://ed-fi.org/ods/identity/claims/course', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/course
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseOffering';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseOffering', 'http://ed-fi.org/ods/identity/claims/courseOffering', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/courseOffering
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseTranscript';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseTranscript', 'http://ed-fi.org/ods/identity/claims/courseTranscript', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/descriptorMapping';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('descriptorMapping', 'http://ed-fi.org/ods/identity/claims/descriptorMapping', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineAction';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineAction', 'http://ed-fi.org/ods/identity/claims/disciplineAction', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineIncident';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncident', 'http://ed-fi.org/ods/identity/claims/disciplineIncident', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationInterventionPrescriptionAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetworkAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationPeerAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('feederSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/feederSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/functionDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('functionDimension', 'http://ed-fi.org/ods/identity/claims/functionDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/fundDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('fundDimension', 'http://ed-fi.org/ods/identity/claims/fundDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/grade'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/grade';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('grade', 'http://ed-fi.org/ods/identity/claims/grade', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradebookEntry';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntry', 'http://ed-fi.org/ods/identity/claims/gradebookEntry', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradingPeriod';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriod', 'http://ed-fi.org/ods/identity/claims/gradingPeriod', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/graduationPlan';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlan', 'http://ed-fi.org/ods/identity/claims/graduationPlan', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/intervention'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/intervention';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('intervention', 'http://ed-fi.org/ods/identity/claims/intervention', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionPrescription';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionPrescription', 'http://ed-fi.org/ods/identity/claims/interventionPrescription', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionStudy';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionStudy', 'http://ed-fi.org/ods/identity/claims/interventionStudy', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/location'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/location';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('location', 'http://ed-fi.org/ods/identity/claims/location', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/location
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/objectDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectDimension', 'http://ed-fi.org/ods/identity/claims/objectDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/openStaffPosition';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('openStaffPosition', 'http://ed-fi.org/ods/identity/claims/openStaffPosition', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalUnitDimension', 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/person'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/person';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('person', 'http://ed-fi.org/ods/identity/claims/person', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEvent', 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/program'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/program';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('program', 'http://ed-fi.org/ods/identity/claims/program', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/program
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programDimension', 'http://ed-fi.org/ods/identity/claims/programDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/projectDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('projectDimension', 'http://ed-fi.org/ods/identity/claims/projectDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportCard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reportCard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportCard', 'http://ed-fi.org/ods/identity/claims/reportCard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/restraintEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEvent', 'http://ed-fi.org/ods/identity/claims/restraintEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/section'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/section';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('section', 'http://ed-fi.org/ods/identity/claims/section', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/section
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionAttendanceTakenEvent', 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/session'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/session';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('session', 'http://ed-fi.org/ods/identity/claims/session', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/session
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sourceDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceDimension', 'http://ed-fi.org/ods/identity/claims/sourceDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffAbsenceEvent', 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffCohortAssociation', 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationContactAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffLeave';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeave', 'http://ed-fi.org/ods/identity/claims/staffLeave', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffProgramAssociation', 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSectionAssociation', 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staffSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAcademicRecord', 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessmentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCohortAssociation', 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCompetencyObjective', 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCTEProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentBehaviorAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentNonOffenderAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationResponsibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentGradebookEntry', 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentHomelessProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAssociation', 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLanguageInstructionProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLearningObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentLearningObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLearningObjective', 'http://ed-fi.org/ods/identity/claims/studentLearningObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentMigrantEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentNeglectedOrDelinquentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentParentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParentAssociation', 'http://ed-fi.org/ods/identity/claims/studentParentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithStudentsOnly';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithStudentsOnly''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithStudentsOnly'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolFoodServiceProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAssociation', 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/studentSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTitleIPartAProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCourseAssociation', 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyProgramAssociation', 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentMetadata', 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessment', 'http://ed-fi.org/ods/identity/claims/assessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItem';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItem', 'http://ed-fi.org/ods/identity/claims/assessmentItem', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentScoreRangeLearningStandard', 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/objectiveAssessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectiveAssessment', 'http://ed-fi.org/ods/identity/claims/objectiveAssessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAssessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessment', 'http://ed-fi.org/ods/identity/claims/studentAssessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/services/identity'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/services/identity';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identity', 'http://ed-fi.org/ods/identity/claims/services/identity', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/services/identity
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/educationStandards';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationStandards', 'http://ed-fi.org/ods/identity/claims/domains/educationStandards', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credential'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credential';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credential', 'http://ed-fi.org/ods/identity/claims/credential', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningObjective', 'http://ed-fi.org/ods/identity/claims/learningObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/learningObjective
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandard', 'http://ed-fi.org/ods/identity/claims/learningStandard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/learningStandard
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceAssociation', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryRelationships', 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsOnly''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsOnly'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationAssignmentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationEmploymentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/studentSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyDomain', 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/survey'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/survey';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('survey', 'http://ed-fi.org/ods/identity/claims/survey', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyQuestion';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestion', 'http://ed-fi.org/ods/identity/claims/surveyQuestion', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestionResponse', 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponse', 'http://ed-fi.org/ods/identity/claims/surveyResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySection'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySection';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySection', 'http://ed-fi.org/ods/identity/claims/surveySection', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponse', 'http://ed-fi.org/ods/identity/claims/surveySectionResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationContent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationContent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationContent', 'http://ed-fi.org/ods/identity/claims/educationContent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationContent
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ COMMIT;
+
+ -- TODO: Remove - For interactive development only
+ -- SELECT dbo.GetAuthorizationMetadataDocument();
+ -- ROLLBACK;
+END $$;
diff --git a/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml
new file mode 100644
index 0000000000..0dd2c3cac1
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml
@@ -0,0 +1,1420 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql
new file mode 100644
index 0000000000..06109497bb
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.sql
@@ -0,0 +1,18287 @@
+
+-- 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.
+
+BEGIN
+ DECLARE
+ @claimId AS INT,
+ @claimName AS nvarchar(max),
+ @parentResourceClaimId AS INT,
+ @existingParentResourceClaimId AS INT,
+ @claimSetId AS INT,
+ @claimSetName AS nvarchar(max),
+ @authorizationStrategyId AS INT,
+ @msg AS nvarchar(max),
+ @createActionId AS INT,
+ @readActionId AS INT,
+ @updateActionId AS INT,
+ @deleteActionId AS INT,
+ @readChangesActionId AS INT,
+ @resourceClaimActionId AS INT,
+ @claimSetResourceClaimActionId AS INT
+
+ DECLARE @claimIdStack AS TABLE (Id INT IDENTITY, ResourceClaimId INT)
+
+ SELECT @createActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Create';
+
+ SELECT @readActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Read';
+
+ SELECT @updateActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Update';
+
+ SELECT @deleteActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'Delete';
+
+ SELECT @readChangesActionId = ActionId
+ FROM [dbo].[Actions] WHERE ActionName = 'ReadChanges';
+
+ BEGIN TRANSACTION
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of root
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('edFiTypes', 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolYearType', 'http://ed-fi.org/ods/identity/claims/schoolYearType', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('systemDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('absenceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicHonorCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicSubjectDescriptor', 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('achievementCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('additionalCreditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('addressTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrationEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrativeFundingControlDescriptor', 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ancestryEthnicOriginDescriptor', 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemResultDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assignmentLateStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attemptStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attendanceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('barrierToInternetAccessInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('behaviorDescriptor', 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('busRouteDescriptor', 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarEventDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('careerPathwayDescriptor', 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterApprovalAgencyTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('citizenshipStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classroomPositionDescriptor', 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortYearTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contactTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contentClassDescriptor', 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('continuationOfServicesReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('costRateDescriptor', 'http://ed-fi.org/ods/identity/claims/costRateDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('countryDescriptor', 'http://ed-fi.org/ods/identity/claims/countryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseAttemptResultDescriptor', 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseDefinedByDescriptor', 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseGPAApplicabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseLevelCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseRepeatCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialFieldDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('crisisTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cteProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('curriculumUsedDescriptor', 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('deliveryMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diagnosisDescriptor', 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDeterminationSourceTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineActionLengthDifferenceReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncidentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('displacedStudentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationalEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationAssociationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationPlanDescriptor', 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('electronicMailTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eligibilityDelayReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eligibilityEvaluationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('employmentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('enrollmentTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryGradeLevelReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('evaluationDelayReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eventCircumstanceDescriptor', 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('exitWithdrawTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('financialCollectionDescriptor', 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradePointAverageTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlanTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gunFreeSchoolsActReportingStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessPrimaryNighttimeResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ideaPartDescriptor', 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identificationDocumentUseDescriptor', 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('immunizationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('incidentLocationDescriptor', 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorGroupDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('institutionTelephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interactivityStyleDescriptor', 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessTypeInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetPerformanceInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionClassDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionEffectivenessRatingDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageDescriptor', 'http://ed-fi.org/ods/identity/claims/languageDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageInstructionProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageUseDescriptor', 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceStrengthDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('levelOfEducationDescriptor', 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('limitedEnglishProficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localeDescriptor', 'http://ed-fi.org/ods/identity/claims/localeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgencyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('magnetSpecialProgramEmphasisSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('mediumOfInstructionDescriptor', 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('methodCreditEarnedDescriptor', 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('migrantEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('modelEntityDescriptor', 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('monitoredDescriptor', 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('networkPurposeDescriptor', 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('nonMedicalImmunizationExemptionDescriptor', 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('otherNameTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationDescriptor', 'http://ed-fi.org/ods/identity/claims/participationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceBaseConversionDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('personalInformationVerificationDescriptor', 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('platformTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('populationServedDescriptor', 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postingResultDescriptor', 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitutionLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAwayFromSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceProviderDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('proficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programAssignmentDescriptor', 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programSponsorDescriptor', 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressDescriptor', 'http://ed-fi.org/ods/identity/claims/progressDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerProfitabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('publicationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('questionFormDescriptor', 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('raceDescriptor', 'http://ed-fi.org/ods/identity/claims/raceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ratingLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonExitedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonNotTestedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('recognitionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationDescriptor', 'http://ed-fi.org/ods/identity/claims/relationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('repeatIdentifierDescriptor', 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reporterDescriptionDescriptor', 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportingTagDescriptor', 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('residencyStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responseIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responsibilityDescriptor', 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEventReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('resultDatatypeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('retestIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceImplementStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolFoodServiceProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationDescriptor', 'http://ed-fi.org/ods/identity/claims/separationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('serviceDescriptor', 'http://ed-fi.org/ods/identity/claims/serviceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sexDescriptor', 'http://ed-fi.org/ods/identity/claims/sexDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationExitReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationSettingDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffClassificationDescriptor', 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeaveEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateAbbreviationDescriptor', 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('submissionStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('supporterMilitaryConnectionDescriptor', 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('technicalSkillsAssessmentDescriptor', 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('telephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('termDescriptor', 'http://ed-fi.org/ods/identity/claims/termDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAParticipantDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartASchoolDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('transportationPublicExpenseEligibilityTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('transportationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('travelDayofWeekDescriptor', 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('travelDirectionDescriptor', 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('tribalAffiliationDescriptor', 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('visaDescriptor', 'http://ed-fi.org/ods/identity/claims/visaDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('weaponDescriptor', 'http://ed-fi.org/ods/identity/claims/weaponDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('managedDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accommodationDescriptor', 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentReportingMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizations', 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityOrganization', 'http://ed-fi.org/ods/identity/claims/communityOrganization', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityOrganization
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProvider', 'http://ed-fi.org/ods/identity/claims/communityProvider', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityProvider
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetwork', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationServiceCenter', 'http://ed-fi.org/ods/identity/claims/educationServiceCenter', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationServiceCenter
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgency', 'http://ed-fi.org/ods/identity/claims/localEducationAgency', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/localEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('organizationDepartment', 'http://ed-fi.org/ods/identity/claims/organizationDepartment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/organizationDepartment
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitution', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/postSecondaryInstitution
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/school'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/school'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('school', 'http://ed-fi.org/ods/identity/claims/school', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/school
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateEducationAgency', 'http://ed-fi.org/ods/identity/claims/stateEducationAgency', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/stateEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/people'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/people'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('people', 'http://ed-fi.org/ods/identity/claims/domains/people', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contact'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/contact'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contact', 'http://ed-fi.org/ods/identity/claims/contact', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staff'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staff'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staff', 'http://ed-fi.org/ods/identity/claims/staff', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staff
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/student'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/student'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('student', 'http://ed-fi.org/ods/identity/claims/student', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/student
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicWeek', 'http://ed-fi.org/ods/identity/claims/academicWeek', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountabilityRating', 'http://ed-fi.org/ods/identity/claims/accountabilityRating', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/accountabilityRating
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('balanceSheetDimension', 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('bellSchedule', 'http://ed-fi.org/ods/identity/claims/bellSchedule', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendar'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendar'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendar', 'http://ed-fi.org/ods/identity/claims/calendar', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarDate', 'http://ed-fi.org/ods/identity/claims/calendarDate', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classPeriod', 'http://ed-fi.org/ods/identity/claims/classPeriod', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/classPeriod
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohort'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/cohort'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohort', 'http://ed-fi.org/ods/identity/claims/cohort', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProviderLicense', 'http://ed-fi.org/ods/identity/claims/communityProviderLicense', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/communityProviderLicense
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyObjective', 'http://ed-fi.org/ods/identity/claims/competencyObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/course'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/course'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('course', 'http://ed-fi.org/ods/identity/claims/course', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/course
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseOffering', 'http://ed-fi.org/ods/identity/claims/courseOffering', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/courseOffering
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseTranscript', 'http://ed-fi.org/ods/identity/claims/courseTranscript', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('descriptorMapping', 'http://ed-fi.org/ods/identity/claims/descriptorMapping', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineAction', 'http://ed-fi.org/ods/identity/claims/disciplineAction', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncident', 'http://ed-fi.org/ods/identity/claims/disciplineIncident', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationInterventionPrescriptionAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetworkAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationPeerAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('evaluationRubricDimension', 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('feederSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/feederSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('functionDimension', 'http://ed-fi.org/ods/identity/claims/functionDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('fundDimension', 'http://ed-fi.org/ods/identity/claims/fundDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/grade'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/grade'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('grade', 'http://ed-fi.org/ods/identity/claims/grade', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntry', 'http://ed-fi.org/ods/identity/claims/gradebookEntry', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriod', 'http://ed-fi.org/ods/identity/claims/gradingPeriod', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlan', 'http://ed-fi.org/ods/identity/claims/graduationPlan', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/intervention'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/intervention'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('intervention', 'http://ed-fi.org/ods/identity/claims/intervention', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionPrescription', 'http://ed-fi.org/ods/identity/claims/interventionPrescription', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionStudy', 'http://ed-fi.org/ods/identity/claims/interventionStudy', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/location'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/location'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('location', 'http://ed-fi.org/ods/identity/claims/location', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/location
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectDimension', 'http://ed-fi.org/ods/identity/claims/objectDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('openStaffPosition', 'http://ed-fi.org/ods/identity/claims/openStaffPosition', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalUnitDimension', 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/person'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/person'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('person', 'http://ed-fi.org/ods/identity/claims/person', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEvent', 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/program'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/program'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('program', 'http://ed-fi.org/ods/identity/claims/program', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/program
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programDimension', 'http://ed-fi.org/ods/identity/claims/programDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programEvaluation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluation', 'http://ed-fi.org/ods/identity/claims/programEvaluation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationElement'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programEvaluationElement'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationElement', 'http://ed-fi.org/ods/identity/claims/programEvaluationElement', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationObjective', 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('projectDimension', 'http://ed-fi.org/ods/identity/claims/projectDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportCard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/reportCard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportCard', 'http://ed-fi.org/ods/identity/claims/reportCard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEvent', 'http://ed-fi.org/ods/identity/claims/restraintEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/section'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/section'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('section', 'http://ed-fi.org/ods/identity/claims/section', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/section
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionAttendanceTakenEvent', 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/session'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/session'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('session', 'http://ed-fi.org/ods/identity/claims/session', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/session
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceDimension', 'http://ed-fi.org/ods/identity/claims/sourceDimension', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffAbsenceEvent', 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffCohortAssociation', 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationContactAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeave', 'http://ed-fi.org/ods/identity/claims/staffLeave', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffProgramAssociation', 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSectionAssociation', 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staffSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAcademicRecord', 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessmentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCohortAssociation', 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCompetencyObjective', 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentContactAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentContactAssociation', 'http://ed-fi.org/ods/identity/claims/studentContactAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCTEProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentBehaviorAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentNonOffenderAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationResponsibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentGradebookEntry', 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentHomelessProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAssociation', 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLanguageInstructionProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentMigrantEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentNeglectedOrDelinquentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramEvaluation', 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolFoodServiceProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAssociation', 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/studentSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramEligibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTitleIPartAProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTransportation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentTransportation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTransportation', 'http://ed-fi.org/ods/identity/claims/studentTransportation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCourseAssociation', 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyProgramAssociation', 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentMetadata', 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessment', 'http://ed-fi.org/ods/identity/claims/assessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItem', 'http://ed-fi.org/ods/identity/claims/assessmentItem', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentScoreRangeLearningStandard', 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectiveAssessment', 'http://ed-fi.org/ods/identity/claims/objectiveAssessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessment', 'http://ed-fi.org/ods/identity/claims/studentAssessment', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/identity'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/identity'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identity', 'http://ed-fi.org/ods/identity/claims/domains/identity', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/identity
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationStandards', 'http://ed-fi.org/ods/identity/claims/domains/educationStandards', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credential'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/credential'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credential', 'http://ed-fi.org/ods/identity/claims/credential', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandard', 'http://ed-fi.org/ods/identity/claims/learningStandard', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/learningStandard
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Assessment Read'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceAssociation', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Bootstrap Descriptors and EdOrgs'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' + '(authorizationStrategyId = ' + CONVERT(nvarchar, @authorizationStrategyId) + ' for ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@claimSetResourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryRelationships', 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsOnly''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsOnly'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationAssignmentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationEmploymentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/studentSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Roster Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyDomain', 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ -- Push claimId to the stack
+ INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId)
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/survey'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/survey'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('survey', 'http://ed-fi.org/ods/identity/claims/survey', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestion', 'http://ed-fi.org/ods/identity/claims/surveyQuestion', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestionResponse', 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponse', 'http://ed-fi.org/ods/identity/claims/surveyResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySection'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySection'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySection', 'http://ed-fi.org/ods/identity/claims/surveySection', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponse', 'http://ed-fi.org/ods/identity/claims/surveySectionResponse', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationContent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimName = 'http://ed-fi.org/ods/identity/claims/educationContent'
+ SET @claimId = NULL
+
+ SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = @claimName
+
+ SELECT @parentResourceClaimId = ResourceClaimId
+ FROM @claimIdStack
+ WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+ IF @claimId IS NULL
+ BEGIN
+ PRINT 'Creating new claim: ' + @claimName
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationContent', 'http://ed-fi.org/ods/identity/claims/educationContent', @parentResourceClaimId)
+
+ SET @claimId = SCOPE_IDENTITY()
+ END
+ ELSE
+ BEGIN
+ IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL)
+ BEGIN
+ PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')'
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = @parentResourceClaimId
+ WHERE ResourceClaimId = @claimId
+ END
+ END
+
+ -- Setting default authorization metadata
+ PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = @claimId
+
+ -- Default Create authorization
+ PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @CreateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Read authorization
+ PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @ReadActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Update authorization
+ PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @UpdateActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Default Delete authorization
+ PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (@claimId, @DeleteActionId)
+
+ SET @resourceClaimActionId = SCOPE_IDENTITY()
+
+
+ SET @authorizationStrategyId = NULL
+
+ SELECT @authorizationStrategyId = a.AuthorizationStrategyId
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased'
+
+ IF @authorizationStrategyId IS NULL
+ BEGIN
+ SET @msg = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ THROW 50000, @msg, 1
+ END
+
+ PRINT 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').'
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (@resourceClaimActionId, @authorizationStrategyId)
+
+
+ -- Processing claim sets for http://ed-fi.org/ods/identity/claims/educationContent
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'Ed-Fi Sandbox'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ SET @claimSetName = 'District Hosted SIS Vendor'
+ SET @claimSetId = NULL
+
+ SELECT @claimSetId = ClaimSetId
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = @claimSetName
+
+ IF @claimSetId IS NULL
+ BEGIN
+ PRINT 'Creating new claim set: ' + @claimSetName
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (@claimSetName)
+
+ SET @claimSetId = SCOPE_IDENTITY()
+ END
+
+ PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.'
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId)
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId
+
+
+ -- Claim set-specific Create authorization
+ PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @CreateActionId) -- Create
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Read authorization
+ PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @ReadActionId) -- Read
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Update authorization
+ PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Claim set-specific Delete authorization
+ PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').'
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete
+
+ SET @claimSetResourceClaimActionId = SCOPE_IDENTITY()
+
+
+
+
+ -- Pop the stack
+ DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack)
+
+
+ COMMIT TRANSACTION
+END
diff --git a/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml
new file mode 100644
index 0000000000..374976f3af
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata.xml
@@ -0,0 +1,1396 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql
new file mode 100644
index 0000000000..38259b2100
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.sql
@@ -0,0 +1,16258 @@
+
+-- 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.
+
+DO $$
+DECLARE
+ claim_id INTEGER;
+ claim_name VARCHAR(2048);
+ parent_resource_claim_id INTEGER;
+ existing_parent_resource_claim_id INTEGER;
+ claim_set_id INTEGER;
+ claim_set_name VARCHAR(255);
+ authorization_strategy_id INTEGER;
+ create_action_id INTEGER;
+ read_action_id INTEGER;
+ update_action_id INTEGER;
+ delete_action_id INTEGER;
+ readchanges_action_id INTEGER;
+ resource_claim_action_id INTEGER;
+ claim_set_resource_claim_action_id INTEGER;
+ claim_id_stack INTEGER ARRAY;
+BEGIN
+ SELECT actionid INTO create_action_id
+ FROM dbo.actions WHERE ActionName = 'Create';
+
+ SELECT actionid INTO read_action_id
+ FROM dbo.actions WHERE ActionName = 'Read';
+
+ SELECT actionid INTO update_action_id
+ FROM dbo.actions WHERE ActionName = 'Update';
+
+ SELECT actionid INTO delete_action_id
+ FROM dbo.actions WHERE ActionName = 'Delete';
+
+ SELECT actionid INTO readchanges_action_id
+ FROM dbo.actions WHERE ActionName = 'ReadChanges';
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of root
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('edFiTypes', 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/edFiTypes
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolYearType'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolYearType';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolYearType', 'http://ed-fi.org/ods/identity/claims/schoolYearType', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('systemDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/systemDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('absenceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/absenceEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicHonorCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/academicHonorCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicSubjectDescriptor', 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('achievementCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/achievementCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('additionalCreditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/additionalCreditTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('addressTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/addressTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrationEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/administrationEnvironmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('administrativeFundingControlDescriptor', 'http://ed-fi.org/ods/identity/claims/administrativeFundingControlDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ancestryEthnicOriginDescriptor', 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItemResultDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assignmentLateStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attemptStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/attemptStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('attendanceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('barrierToInternetAccessInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('behaviorDescriptor', 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('busRouteDescriptor', 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarEventDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('careerPathwayDescriptor', 'http://ed-fi.org/ods/identity/claims/careerPathwayDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterApprovalAgencyTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/charterApprovalAgencyTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('charterStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('citizenshipStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classroomPositionDescriptor', 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohortYearTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contactTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contentClassDescriptor', 'http://ed-fi.org/ods/identity/claims/contentClassDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('continuationOfServicesReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/continuationOfServicesReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/costRateDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/costRateDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('costRateDescriptor', 'http://ed-fi.org/ods/identity/claims/costRateDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/countryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/countryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('countryDescriptor', 'http://ed-fi.org/ods/identity/claims/countryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseAttemptResultDescriptor', 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseDefinedByDescriptor', 'http://ed-fi.org/ods/identity/claims/courseDefinedByDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseGPAApplicabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/courseGPAApplicabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/courseIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseLevelCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseRepeatCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialFieldDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credentialTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/creditCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('creditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('crisisTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cteProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/cteProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('curriculumUsedDescriptor', 'http://ed-fi.org/ods/identity/claims/curriculumUsedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('deliveryMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diagnosisDescriptor', 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('diplomaTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/diplomaTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDesignationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disabilityDeterminationSourceTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineActionLengthDifferenceReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncidentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('displacedStudentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/displacedStudentStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationalEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationAssociationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationPlanDescriptor', 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('electronicMailTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eligibilityDelayReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/eligibilityDelayReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eligibilityEvaluationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/eligibilityEvaluationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('employmentStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/employmentStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('enrollmentTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/enrollmentTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryGradeLevelReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/entryGradeLevelReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('entryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/entryTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('evaluationDelayReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('eventCircumstanceDescriptor', 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('exitWithdrawTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('financialCollectionDescriptor', 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradePointAverageTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradePointAverageTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlanTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gunFreeSchoolsActReportingStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/gunFreeSchoolsActReportingStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessPrimaryNighttimeResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessPrimaryNighttimeResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('homelessProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/homelessProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ideaPartDescriptor', 'http://ed-fi.org/ods/identity/claims/ideaPartDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identificationDocumentUseDescriptor', 'http://ed-fi.org/ods/identity/claims/identificationDocumentUseDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('immunizationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/immunizationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('incidentLocationDescriptor', 'http://ed-fi.org/ods/identity/claims/incidentLocationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorGroupDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorGroupDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('indicatorLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/indicatorLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('institutionTelephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/institutionTelephoneNumberTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interactivityStyleDescriptor', 'http://ed-fi.org/ods/identity/claims/interactivityStyleDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetAccessTypeInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetAccessTypeInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('internetPerformanceInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionClassDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionEffectivenessRatingDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageDescriptor', 'http://ed-fi.org/ods/identity/claims/languageDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageInstructionProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/languageInstructionProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('languageUseDescriptor', 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceStrengthDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardScopeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('levelOfEducationDescriptor', 'http://ed-fi.org/ods/identity/claims/levelOfEducationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('licenseTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/licenseTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('limitedEnglishProficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localeDescriptor', 'http://ed-fi.org/ods/identity/claims/localeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgencyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('magnetSpecialProgramEmphasisSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('mediumOfInstructionDescriptor', 'http://ed-fi.org/ods/identity/claims/mediumOfInstructionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('methodCreditEarnedDescriptor', 'http://ed-fi.org/ods/identity/claims/methodCreditEarnedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('migrantEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/migrantEducationProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('modelEntityDescriptor', 'http://ed-fi.org/ods/identity/claims/modelEntityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('monitoredDescriptor', 'http://ed-fi.org/ods/identity/claims/monitoredDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('neglectedOrDelinquentProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/neglectedOrDelinquentProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('networkPurposeDescriptor', 'http://ed-fi.org/ods/identity/claims/networkPurposeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('nonMedicalImmunizationExemptionDescriptor', 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('otherNameTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/participationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationDescriptor', 'http://ed-fi.org/ods/identity/claims/participationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('participationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/participationStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceBaseConversionDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceBaseConversionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('personalInformationVerificationDescriptor', 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('platformTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/platformTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('populationServedDescriptor', 'http://ed-fi.org/ods/identity/claims/populationServedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postingResultDescriptor', 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitutionLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAccessDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAccessDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceAwayFromSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceAwayFromSchoolDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryLearningDeviceProviderDescriptor', 'http://ed-fi.org/ods/identity/claims/primaryLearningDeviceProviderDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('proficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programAssignmentDescriptor', 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programEvaluationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programSponsorDescriptor', 'http://ed-fi.org/ods/identity/claims/programSponsorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/programTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/progressDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressDescriptor', 'http://ed-fi.org/ods/identity/claims/progressDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('progressLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerProfitabilityDescriptor', 'http://ed-fi.org/ods/identity/claims/providerProfitabilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('providerStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/providerStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('publicationStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/publicationStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('questionFormDescriptor', 'http://ed-fi.org/ods/identity/claims/questionFormDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/raceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/raceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('raceDescriptor', 'http://ed-fi.org/ods/identity/claims/raceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('ratingLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/ratingLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonExitedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonExitedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reasonNotTestedDescriptor', 'http://ed-fi.org/ods/identity/claims/reasonNotTestedDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('recognitionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/recognitionTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/relationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/relationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationDescriptor', 'http://ed-fi.org/ods/identity/claims/relationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('repeatIdentifierDescriptor', 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reporterDescriptionDescriptor', 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportingTagDescriptor', 'http://ed-fi.org/ods/identity/claims/reportingTagDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('residencyStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/residencyStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responseIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/responseIndicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('responsibilityDescriptor', 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEventReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('resultDatatypeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/resultDatatypeTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('retestIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceBasisDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolChoiceImplementStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolChoiceImplementStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolFoodServiceProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolFoodServiceProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('schoolTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/separationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationDescriptor', 'http://ed-fi.org/ods/identity/claims/separationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('separationReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/separationReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/serviceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/serviceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('serviceDescriptor', 'http://ed-fi.org/ods/identity/claims/serviceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sexDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sexDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sexDescriptor', 'http://ed-fi.org/ods/identity/claims/sexDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationExitReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationExitReasonDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('specialEducationSettingDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffClassificationDescriptor', 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeaveEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateAbbreviationDescriptor', 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('submissionStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('supporterMilitaryConnectionDescriptor', 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('teachingCredentialDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('technicalSkillsAssessmentDescriptor', 'http://ed-fi.org/ods/identity/claims/technicalSkillsAssessmentDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('telephoneNumberTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/telephoneNumberTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/termDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/termDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('termDescriptor', 'http://ed-fi.org/ods/identity/claims/termDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAParticipantDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAParticipantDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartAProgramServiceDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartAProgramServiceDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('titleIPartASchoolDesignationDescriptor', 'http://ed-fi.org/ods/identity/claims/titleIPartASchoolDesignationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('transportationPublicExpenseEligibilityTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/transportationPublicExpenseEligibilityTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('transportationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/transportationTypeDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('travelDayofWeekDescriptor', 'http://ed-fi.org/ods/identity/claims/travelDayofWeekDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('travelDirectionDescriptor', 'http://ed-fi.org/ods/identity/claims/travelDirectionDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('tribalAffiliationDescriptor', 'http://ed-fi.org/ods/identity/claims/tribalAffiliationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/visaDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/visaDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('visaDescriptor', 'http://ed-fi.org/ods/identity/claims/visaDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/weaponDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/weaponDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('weaponDescriptor', 'http://ed-fi.org/ods/identity/claims/weaponDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('managedDescriptors', 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/managedDescriptors
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accommodationDescriptor', 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentPeriodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentReportingMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('performanceLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizations', 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationOrganizations
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityOrganization'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityOrganization';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityOrganization', 'http://ed-fi.org/ods/identity/claims/communityOrganization', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityOrganization
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProvider'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityProvider';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProvider', 'http://ed-fi.org/ods/identity/claims/communityProvider', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityProvider
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetwork', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationServiceCenter'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationServiceCenter';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationServiceCenter', 'http://ed-fi.org/ods/identity/claims/educationServiceCenter', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationServiceCenter
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/localEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/localEducationAgency';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('localEducationAgency', 'http://ed-fi.org/ods/identity/claims/localEducationAgency', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/localEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/organizationDepartment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/organizationDepartment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('organizationDepartment', 'http://ed-fi.org/ods/identity/claims/organizationDepartment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/organizationDepartment
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryInstitution', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/postSecondaryInstitution
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/school'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/school';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('school', 'http://ed-fi.org/ods/identity/claims/school', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/school
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/stateEducationAgency'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/stateEducationAgency';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('stateEducationAgency', 'http://ed-fi.org/ods/identity/claims/stateEducationAgency', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/stateEducationAgency
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/people'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/people';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('people', 'http://ed-fi.org/ods/identity/claims/domains/people', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/people
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/contact'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/contact';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('contact', 'http://ed-fi.org/ods/identity/claims/contact', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staff'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staff';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staff', 'http://ed-fi.org/ods/identity/claims/staff', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staff
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/student'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/student';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('student', 'http://ed-fi.org/ods/identity/claims/student', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/student
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/academicWeek'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/academicWeek';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('academicWeek', 'http://ed-fi.org/ods/identity/claims/academicWeek', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/accountabilityRating'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/accountabilityRating';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('accountabilityRating', 'http://ed-fi.org/ods/identity/claims/accountabilityRating', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/accountabilityRating
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('balanceSheetDimension', 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/bellSchedule'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/bellSchedule';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('bellSchedule', 'http://ed-fi.org/ods/identity/claims/bellSchedule', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendar'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendar';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendar', 'http://ed-fi.org/ods/identity/claims/calendar', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/calendarDate'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/calendarDate';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('calendarDate', 'http://ed-fi.org/ods/identity/claims/calendarDate', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/classPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/classPeriod';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('classPeriod', 'http://ed-fi.org/ods/identity/claims/classPeriod', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/classPeriod
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/cohort'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/cohort';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('cohort', 'http://ed-fi.org/ods/identity/claims/cohort', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/communityProviderLicense'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/communityProviderLicense';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('communityProviderLicense', 'http://ed-fi.org/ods/identity/claims/communityProviderLicense', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/communityProviderLicense
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/competencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/competencyObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('competencyObjective', 'http://ed-fi.org/ods/identity/claims/competencyObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/course'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/course';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('course', 'http://ed-fi.org/ods/identity/claims/course', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/course
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseOffering'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseOffering';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseOffering', 'http://ed-fi.org/ods/identity/claims/courseOffering', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/courseOffering
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/courseTranscript'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/courseTranscript';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('courseTranscript', 'http://ed-fi.org/ods/identity/claims/courseTranscript', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/descriptorMapping'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/descriptorMapping';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('descriptorMapping', 'http://ed-fi.org/ods/identity/claims/descriptorMapping', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineAction'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineAction';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineAction', 'http://ed-fi.org/ods/identity/claims/disciplineAction', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/disciplineIncident'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/disciplineIncident';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('disciplineIncident', 'http://ed-fi.org/ods/identity/claims/disciplineIncident', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationInterventionPrescriptionAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationNetworkAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationOrganizationPeerAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('evaluationRubricDimension', 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('feederSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/feederSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/functionDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/functionDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('functionDimension', 'http://ed-fi.org/ods/identity/claims/functionDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/fundDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/fundDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('fundDimension', 'http://ed-fi.org/ods/identity/claims/fundDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/grade'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/grade';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('grade', 'http://ed-fi.org/ods/identity/claims/grade', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradebookEntry';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradebookEntry', 'http://ed-fi.org/ods/identity/claims/gradebookEntry', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/gradingPeriod'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/gradingPeriod';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('gradingPeriod', 'http://ed-fi.org/ods/identity/claims/gradingPeriod', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/graduationPlan'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/graduationPlan';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('graduationPlan', 'http://ed-fi.org/ods/identity/claims/graduationPlan', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/intervention'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/intervention';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('intervention', 'http://ed-fi.org/ods/identity/claims/intervention', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionPrescription'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionPrescription';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionPrescription', 'http://ed-fi.org/ods/identity/claims/interventionPrescription', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/interventionStudy'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/interventionStudy';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('interventionStudy', 'http://ed-fi.org/ods/identity/claims/interventionStudy', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/location'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/location';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('location', 'http://ed-fi.org/ods/identity/claims/location', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/location
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/objectDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectDimension', 'http://ed-fi.org/ods/identity/claims/objectDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/openStaffPosition'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/openStaffPosition';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('openStaffPosition', 'http://ed-fi.org/ods/identity/claims/openStaffPosition', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('operationalUnitDimension', 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/person'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/person';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('person', 'http://ed-fi.org/ods/identity/claims/person', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('postSecondaryEvent', 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/program'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/program';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('program', 'http://ed-fi.org/ods/identity/claims/program', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/program
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programDimension', 'http://ed-fi.org/ods/identity/claims/programDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programEvaluation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluation', 'http://ed-fi.org/ods/identity/claims/programEvaluation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationElement'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programEvaluationElement';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationElement', 'http://ed-fi.org/ods/identity/claims/programEvaluationElement', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('programEvaluationObjective', 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/projectDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/projectDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('projectDimension', 'http://ed-fi.org/ods/identity/claims/projectDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/reportCard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/reportCard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('reportCard', 'http://ed-fi.org/ods/identity/claims/reportCard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/restraintEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/restraintEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('restraintEvent', 'http://ed-fi.org/ods/identity/claims/restraintEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/section'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/section';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('section', 'http://ed-fi.org/ods/identity/claims/section', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/section
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sectionAttendanceTakenEvent', 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/session'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/session';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('session', 'http://ed-fi.org/ods/identity/claims/session', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/session
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/sourceDimension'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/sourceDimension';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('sourceDimension', 'http://ed-fi.org/ods/identity/claims/sourceDimension', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffAbsenceEvent', 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffCohortAssociation', 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationContactAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffLeave'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffLeave';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffLeave', 'http://ed-fi.org/ods/identity/claims/staffLeave', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffProgramAssociation', 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffSectionAssociation', 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staffSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAcademicRecord', 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessmentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCohortAssociation', 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCompetencyObjective', 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentContactAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentContactAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentContactAssociation', 'http://ed-fi.org/ods/identity/claims/studentContactAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentCTEProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentBehaviorAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentDisciplineIncidentNonOffenderAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentEducationOrganizationResponsibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentGradebookEntry', 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentHomelessProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAssociation', 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentInterventionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentLanguageInstructionProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentMigrantEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentNeglectedOrDelinquentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentProgramEvaluation', 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolFoodServiceProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAssociation', 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/studentSectionAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSectionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSpecialEducationProgramEligibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTitleIPartAProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentTransportation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentTransportation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentTransportation', 'http://ed-fi.org/ods/identity/claims/studentTransportation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyCourseAssociation', 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyProgramAssociation', 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentMetadata', 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessment', 'http://ed-fi.org/ods/identity/claims/assessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentItem'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentItem';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentItem', 'http://ed-fi.org/ods/identity/claims/assessmentItem', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('assessmentScoreRangeLearningStandard', 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/objectiveAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/objectiveAssessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('objectiveAssessment', 'http://ed-fi.org/ods/identity/claims/objectiveAssessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentAssessment'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentAssessment';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentAssessment', 'http://ed-fi.org/ods/identity/claims/studentAssessment', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/identity'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/identity';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('identity', 'http://ed-fi.org/ods/identity/claims/domains/identity', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/identity
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/educationStandards'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/educationStandards';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationStandards', 'http://ed-fi.org/ods/identity/claims/domains/educationStandards', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/educationStandards
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/credential'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/credential';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('credential', 'http://ed-fi.org/ods/identity/claims/credential', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NoFurtherAuthorizationRequired'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandard'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandard';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandard', 'http://ed-fi.org/ods/identity/claims/learningStandard', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/learningStandard
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Assessment Read'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Assessment Read';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('learningStandardEquivalenceAssociation', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Bootstrap Descriptors and EdOrgs'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Bootstrap Descriptors and EdOrgs';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NoFurtherAuthorizationRequired''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Creating authorization strategy override entry of ''NoFurtherAuthorizationRequired''' || '(authorizationStrategyId = ' || authorization_strategy_id || ' for ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides(ClaimSetResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (claim_set_resource_claim_action_id, authorization_strategy_id);
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('primaryRelationships', 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsOnly''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsOnly'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/primaryRelationships
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationAssignmentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('staffEducationOrganizationEmploymentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('studentSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/studentSchoolAssociation
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Roster Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Roster Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyDomain', 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ -- Push claimId to the stack
+ claim_id_stack := array_append(claim_id_stack, claim_id);
+
+ -- Processing children of http://ed-fi.org/ods/identity/claims/domains/surveyDomain
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/survey'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/survey';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('survey', 'http://ed-fi.org/ods/identity/claims/survey', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestion'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyQuestion';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestion', 'http://ed-fi.org/ods/identity/claims/surveyQuestion', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyQuestionResponse', 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveyResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveyResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveyResponse', 'http://ed-fi.org/ods/identity/claims/surveyResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySection'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySection';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySection', 'http://ed-fi.org/ods/identity/claims/surveySection', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/surveySectionResponse'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/surveySectionResponse';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('surveySectionResponse', 'http://ed-fi.org/ods/identity/claims/surveySectionResponse', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/educationContent'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_name := 'http://ed-fi.org/ods/identity/claims/educationContent';
+ claim_id := NULL;
+
+ SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id
+ FROM dbo.ResourceClaims
+ WHERE ClaimName = claim_name;
+
+ parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)];
+
+ IF claim_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim: %', claim_name;
+
+ INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId)
+ VALUES ('educationContent', 'http://ed-fi.org/ods/identity/claims/educationContent', parent_resource_claim_id)
+ RETURNING ResourceClaimId
+ INTO claim_id;
+ ELSE
+ IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN
+ RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')';
+
+ UPDATE dbo.ResourceClaims
+ SET ParentResourceClaimId = parent_resource_claim_id
+ WHERE ResourceClaimId = claim_id;
+ END IF;
+ END IF;
+
+ -- Setting default authorization metadata
+ RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies
+ WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ResourceClaimActions
+ WHERE ResourceClaimId = claim_id;
+
+
+ -- Default Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Create_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Read_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Update_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Default Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+
+ INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId)
+ VALUES (claim_id, Delete_action_id)
+ RETURNING ResourceClaimActionId
+ INTO resource_claim_action_id;
+
+
+ authorization_strategy_id := NULL;
+
+ SELECT a.AuthorizationStrategyId INTO authorization_strategy_id
+ FROM dbo.AuthorizationStrategies a
+ WHERE a.AuthorizationStrategyName = 'NamespaceBased';
+
+ IF authorization_strategy_id IS NULL THEN
+ RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''NamespaceBased''';
+ END IF;
+
+ RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''NamespaceBased'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').';
+ INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId)
+ VALUES (resource_claim_action_id, authorization_strategy_id);
+
+ -- Processing claimsets for http://ed-fi.org/ods/identity/claims/educationContent
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'Ed-Fi Sandbox'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'Ed-Fi Sandbox';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+ ----------------------------------------------------------------------------------------------------------------------------
+ -- Claim set: 'District Hosted SIS Vendor'
+ ----------------------------------------------------------------------------------------------------------------------------
+ claim_set_name := 'District Hosted SIS Vendor';
+ claim_set_id := NULL;
+
+ SELECT ClaimSetId INTO claim_set_id
+ FROM dbo.ClaimSets
+ WHERE ClaimSetName = claim_set_name;
+
+ IF claim_set_id IS NULL THEN
+ RAISE NOTICE 'Creating new claim set: %', claim_set_name;
+
+ INSERT INTO dbo.ClaimSets(ClaimSetName)
+ VALUES (claim_set_name)
+ RETURNING ClaimSetId
+ INTO claim_set_id;
+ END IF;
+
+
+ RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.';
+
+ DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
+ WHERE ClaimSetResourceClaimActionId IN (
+ SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id);
+
+ DELETE FROM dbo.ClaimSetResourceClaimActions
+ WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id;
+
+
+
+ -- Claim set-specific Create authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Create_action_id) -- Create
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Read authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Read_action_id) -- Read
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Update authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Update_action_id) -- Update
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Claim set-specific Delete authorization
+ RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').';
+
+ INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId)
+ VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete
+ RETURNING ClaimSetResourceClaimActionId
+ INTO claim_set_resource_claim_action_id;
+
+
+
+
+ -- Pop the stack
+ claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]);
+
+ COMMIT;
+
+ -- TODO: Remove - For interactive development only
+ -- SELECT dbo.GetAuthorizationMetadataDocument();
+ -- ROLLBACK;
+END $$;
diff --git a/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml
new file mode 100644
index 0000000000..374976f3af
--- /dev/null
+++ b/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata.xml
@@ -0,0 +1,1396 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/4.0.0/DataStandard_400_ApprovalTests.Generated_File_List.Standard.4.0.0.approved.txt b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/4.0.0/DataStandard_400_ApprovalTests.Generated_File_List.Standard.4.0.0.approved.txt
index 254bd93acb..dd1c77a704 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/4.0.0/DataStandard_400_ApprovalTests.Generated_File_List.Standard.4.0.0.approved.txt
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/4.0.0/DataStandard_400_ApprovalTests.Generated_File_List.Standard.4.0.0.approved.txt
@@ -53,8 +53,6 @@ Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/4.0
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/4.0.0/Pipelines/CreateOrUpdatePipelines.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/4.0.0/Requests/Requests.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/4.0.0/Resources/Resources.generated.cs
-Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata_generated.sql
-Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/4.0.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata_generated.sql
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/4.0.0/Controllers/Controllers.generated.cs
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/4.0.0/EntityOrmMappings/MsSql/EntityOrmMappings.generated.hbm.xml
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/4.0.0/EntityOrmMappings/MsSql/EntityOrmMappingsForQueries.generated.hbm.xml
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Generated_File_List.Standard.5.1.0.approved.txt b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Generated_File_List.Standard.5.1.0.approved.txt
index 20faa723f9..695c978f79 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Generated_File_List.Standard.5.1.0.approved.txt
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Generated_File_List.Standard.5.1.0.approved.txt
@@ -1,4 +1,4 @@
-Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.Homograph/Versions/1.0.0/Standard/5.1.0/Authorization/EntityAuthorizationContextProviders.generated.cs
+Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.Homograph/Versions/1.0.0/Standard/5.1.0/Authorization/EntityAuthorizationContextProviders.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.Homograph/Versions/1.0.0/Standard/5.1.0/Controllers/Controllers.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.Homograph/Versions/1.0.0/Standard/5.1.0/EntityOrmMappings/MsSql/EntityOrmMappings.generated.hbm.xml
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.Homograph/Versions/1.0.0/Standard/5.1.0/EntityOrmMappings/PgSql/EntityOrmMappings.generated.hbm.xml
@@ -53,8 +53,6 @@ Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/5.1
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/5.1.0/Pipelines/CreateOrUpdatePipelines.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/5.1.0/Requests/Requests.generated.cs
Ed-Fi-Extensions/Extensions/EdFi.Ods.Extensions.TPDM/Versions/1.1.0/Standard/5.1.0/Resources/Resources.generated.cs
-Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/MsSql/Data/Security/0002-ResourceClaimMetadata_generated.sql
-Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/5.1.0/Artifacts/PgSql/Data/Security/0002-ResourceClaimMetadata_generated.sql
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/5.1.0/Controllers/Controllers.generated.cs
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/5.1.0/EntityOrmMappings/MsSql/EntityOrmMappings.generated.hbm.xml
Ed-Fi-ODS/Application/EdFi.Ods.Standard/Standard/5.1.0/EntityOrmMappings/MsSql/EntityOrmMappingsForQueries.generated.hbm.xml
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_MsSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_MsSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
index 9fd1fab42b..fbb6b6ae4a 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_MsSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_MsSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
@@ -79,15 +79,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/academicWeek')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'academicWeek', N'http://ed-fi.org/ods/identity/claims/academicWeek',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor')
BEGIN
@@ -97,15 +88,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/accountabilityRating')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'accountabilityRating', N'http://ed-fi.org/ods/identity/claims/accountabilityRating',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor')
BEGIN
@@ -169,15 +151,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assessment')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'assessment', N'http://ed-fi.org/ods/identity/claims/assessment',
-@assessmentMetadataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor')
BEGIN
@@ -196,15 +169,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assessmentItem')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'assessmentItem', N'http://ed-fi.org/ods/identity/claims/assessmentItem',
-@assessmentMetadataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor')
BEGIN
@@ -241,15 +205,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'assessmentScoreRangeLearningStandard', N'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard',
-@assessmentMetadataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor')
BEGIN
@@ -277,15 +232,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'balanceSheetDimension', N'http://ed-fi.org/ods/identity/claims/balanceSheetDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor')
BEGIN
@@ -304,15 +250,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/bellSchedule')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'bellSchedule', N'http://ed-fi.org/ods/identity/claims/bellSchedule',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor')
BEGIN
@@ -322,24 +259,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/calendar')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'calendar', N'http://ed-fi.org/ods/identity/claims/calendar',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/calendarDate')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'calendarDate', N'http://ed-fi.org/ods/identity/claims/calendarDate',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor')
BEGIN
@@ -385,15 +304,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/chartOfAccount')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'chartOfAccount', N'http://ed-fi.org/ods/identity/claims/chartOfAccount',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor')
BEGIN
@@ -403,15 +313,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/classPeriod')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'classPeriod', N'http://ed-fi.org/ods/identity/claims/classPeriod',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor')
BEGIN
@@ -421,15 +322,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/cohort')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'cohort', N'http://ed-fi.org/ods/identity/claims/cohort',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor')
BEGIN
@@ -457,33 +349,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/communityOrganization')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'communityOrganization', N'http://ed-fi.org/ods/identity/claims/communityOrganization',
-@educationOrganizationsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/communityProvider')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'communityProvider', N'http://ed-fi.org/ods/identity/claims/communityProvider',
-@educationOrganizationsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/communityProviderLicense')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'communityProviderLicense', N'http://ed-fi.org/ods/identity/claims/communityProviderLicense',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor')
BEGIN
@@ -493,24 +358,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/competencyObjective')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'competencyObjective', N'http://ed-fi.org/ods/identity/claims/competencyObjective',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/contact')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'contact', N'http://ed-fi.org/ods/identity/claims/contact',
-@peopleResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor')
BEGIN
@@ -556,15 +403,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/course')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'course', N'http://ed-fi.org/ods/identity/claims/course',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor')
BEGIN
@@ -610,15 +448,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/courseOffering')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'courseOffering', N'http://ed-fi.org/ods/identity/claims/courseOffering',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor')
BEGIN
@@ -628,24 +457,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/courseTranscript')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'courseTranscript', N'http://ed-fi.org/ods/identity/claims/courseTranscript',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/credential')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'credential', N'http://ed-fi.org/ods/identity/claims/credential',
-@educationStandardsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor')
BEGIN
@@ -682,15 +493,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/crisisEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'crisisEvent', N'http://ed-fi.org/ods/identity/claims/crisisEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor')
BEGIN
@@ -727,15 +529,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/descriptorMapping')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'descriptorMapping', N'http://ed-fi.org/ods/identity/claims/descriptorMapping',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor')
BEGIN
@@ -790,15 +583,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/disciplineAction')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'disciplineAction', N'http://ed-fi.org/ods/identity/claims/disciplineAction',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor')
BEGIN
@@ -817,15 +601,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/disciplineIncident')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'disciplineIncident', N'http://ed-fi.org/ods/identity/claims/disciplineIncident',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor')
BEGIN
@@ -853,15 +628,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationContent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationContent', N'http://ed-fi.org/ods/identity/claims/educationContent',
-NULL);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor')
BEGIN
@@ -889,42 +655,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationOrganizationInterventionPrescriptionAssociation', N'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationOrganizationNetwork', N'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork',
-@educationOrganizationsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationOrganizationNetworkAssociation', N'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationOrganizationPeerAssociation', N'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor')
BEGIN
@@ -934,15 +664,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/educationServiceCenter')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'educationServiceCenter', N'http://ed-fi.org/ods/identity/claims/educationServiceCenter',
-@educationOrganizationsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor')
BEGIN
@@ -1015,15 +736,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'evaluationRubricDimension', N'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor')
BEGIN
@@ -1042,15 +754,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'feederSchoolAssociation', N'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor')
BEGIN
@@ -1060,42 +763,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/functionDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'functionDimension', N'http://ed-fi.org/ods/identity/claims/functionDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/fundDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'fundDimension', N'http://ed-fi.org/ods/identity/claims/fundDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/grade')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'grade', N'http://ed-fi.org/ods/identity/claims/grade',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/gradebookEntry')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'gradebookEntry', N'http://ed-fi.org/ods/identity/claims/gradebookEntry',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor')
BEGIN
@@ -1132,15 +799,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/gradingPeriod')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'gradingPeriod', N'http://ed-fi.org/ods/identity/claims/gradingPeriod',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor')
BEGIN
@@ -1150,15 +808,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/graduationPlan')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'graduationPlan', N'http://ed-fi.org/ods/identity/claims/graduationPlan',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor')
BEGIN
@@ -1303,15 +952,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/intervention')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'intervention', N'http://ed-fi.org/ods/identity/claims/intervention',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor')
BEGIN
@@ -1330,24 +970,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/interventionPrescription')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'interventionPrescription', N'http://ed-fi.org/ods/identity/claims/interventionPrescription',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/interventionStudy')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'interventionStudy', N'http://ed-fi.org/ods/identity/claims/interventionStudy',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/languageDescriptor')
BEGIN
@@ -1375,30 +997,12 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/learningStandard')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'learningStandard', N'http://ed-fi.org/ods/identity/claims/learningStandard',
-@educationStandardsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'learningStandardCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'learningStandardEquivalenceAssociation', N'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation',
-@educationStandardsResourceClaimId);
+ VALUES (N'learningStandardCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor',
+@systemDescriptorsResourceClaimId);
END
@@ -1456,42 +1060,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localAccount')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localAccount', N'http://ed-fi.org/ods/identity/claims/localAccount',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localActual')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localActual', N'http://ed-fi.org/ods/identity/claims/localActual',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localBudget')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localBudget', N'http://ed-fi.org/ods/identity/claims/localBudget',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localContractedStaff')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localContractedStaff', N'http://ed-fi.org/ods/identity/claims/localContractedStaff',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localeDescriptor')
BEGIN
@@ -1501,15 +1069,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localEducationAgency')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localEducationAgency', N'http://ed-fi.org/ods/identity/claims/localEducationAgency',
-@educationOrganizationsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor')
BEGIN
@@ -1519,33 +1078,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localEncumbrance')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localEncumbrance', N'http://ed-fi.org/ods/identity/claims/localEncumbrance',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/localPayroll')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'localPayroll', N'http://ed-fi.org/ods/identity/claims/localPayroll',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/location')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'location', N'http://ed-fi.org/ods/identity/claims/location',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor')
BEGIN
@@ -1636,33 +1168,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/objectDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'objectDimension', N'http://ed-fi.org/ods/identity/claims/objectDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/objectiveAssessment')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'objectiveAssessment', N'http://ed-fi.org/ods/identity/claims/objectiveAssessment',
-@assessmentMetadataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/openStaffPosition')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'openStaffPosition', N'http://ed-fi.org/ods/identity/claims/openStaffPosition',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor')
BEGIN
@@ -1672,24 +1177,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'operationalUnitDimension', N'http://ed-fi.org/ods/identity/claims/operationalUnitDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/organizationDepartment')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'organizationDepartment', N'http://ed-fi.org/ods/identity/claims/organizationDepartment',
-@educationOrganizationsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor')
BEGIN
@@ -1735,15 +1222,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/person')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'person', N'http://ed-fi.org/ods/identity/claims/person',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor')
BEGIN
@@ -1780,15 +1258,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'postSecondaryEvent', N'http://ed-fi.org/ods/identity/claims/postSecondaryEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor')
BEGIN
@@ -1798,15 +1267,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'postSecondaryInstitution', N'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution',
-@educationOrganizationsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor')
BEGIN
@@ -1852,15 +1312,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/program')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'program', N'http://ed-fi.org/ods/identity/claims/program',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor')
BEGIN
@@ -1879,42 +1330,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'programDimension', N'http://ed-fi.org/ods/identity/claims/programDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programEvaluation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'programEvaluation', N'http://ed-fi.org/ods/identity/claims/programEvaluation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programEvaluationElement')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'programEvaluationElement', N'http://ed-fi.org/ods/identity/claims/programEvaluationElement',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'programEvaluationObjective', N'http://ed-fi.org/ods/identity/claims/programEvaluationObjective',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor')
BEGIN
@@ -1969,15 +1384,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/projectDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'projectDimension', N'http://ed-fi.org/ods/identity/claims/projectDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor')
BEGIN
@@ -2086,15 +1492,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/reportCard')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'reportCard', N'http://ed-fi.org/ods/identity/claims/reportCard',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor')
BEGIN
@@ -2140,15 +1537,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/restraintEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'restraintEvent', N'http://ed-fi.org/ods/identity/claims/restraintEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor')
BEGIN
@@ -2176,15 +1564,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/school')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'school', N'http://ed-fi.org/ods/identity/claims/school',
-@educationOrganizationsResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor')
BEGIN
@@ -2230,33 +1609,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/schoolYearType')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'schoolYearType', N'http://ed-fi.org/ods/identity/claims/schoolYearType',
-@typesResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/section')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'section', N'http://ed-fi.org/ods/identity/claims/section',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'sectionAttendanceTakenEvent', N'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor')
BEGIN
@@ -2302,15 +1654,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/session')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'session', N'http://ed-fi.org/ods/identity/claims/session',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/sexDescriptor')
BEGIN
@@ -2320,15 +1663,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/sourceDimension')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'sourceDimension', N'http://ed-fi.org/ods/identity/claims/sourceDimension',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor')
BEGIN
@@ -2365,24 +1699,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staff')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staff', N'http://ed-fi.org/ods/identity/claims/staff',
-@peopleResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffAbsenceEvent', N'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor')
BEGIN
@@ -2392,484 +1708,88 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffCohortAssociation', N'http://ed-fi.org/ods/identity/claims/staffCohortAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffDisciplineIncidentAssociation', N'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffEducationOrganizationAssignmentAssociation', N'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation',
-@primaryRelationshipsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffEducationOrganizationContactAssociation', N'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation',
-@relationshipBasedDataResourceClaimId);
+ VALUES (N'staffIdentificationSystemDescriptor', N'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffEducationOrganizationEmploymentAssociation', N'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation',
-@primaryRelationshipsResourceClaimId);
+ VALUES (N'staffLeaveEventCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffIdentificationSystemDescriptor', N'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor',
+ VALUES (N'stateAbbreviationDescriptor', N'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor',
@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffLeave')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffLeave', N'http://ed-fi.org/ods/identity/claims/staffLeave',
-@relationshipBasedDataResourceClaimId);
+ VALUES (N'studentCharacteristicDescriptor', N'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffLeaveEventCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor',
+ VALUES (N'studentIdentificationSystemDescriptor', N'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor',
@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffProgramAssociation', N'http://ed-fi.org/ods/identity/claims/staffProgramAssociation',
-@relationshipBasedDataResourceClaimId);
+ VALUES (N'studentParticipationCodeDescriptor', N'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffSchoolAssociation', N'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation',
-@relationshipBasedDataResourceClaimId);
+ VALUES (N'submissionStatusDescriptor', N'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'staffSectionAssociation', N'http://ed-fi.org/ods/identity/claims/staffSectionAssociation',
-@relationshipBasedDataResourceClaimId);
+ VALUES (N'supporterMilitaryConnectionDescriptor', N'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor',
+@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'stateAbbreviationDescriptor', N'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor',
+ VALUES (N'surveyCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor',
@systemDescriptorsResourceClaimId);
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/stateEducationAgency')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'stateEducationAgency', N'http://ed-fi.org/ods/identity/claims/stateEducationAgency',
-@educationOrganizationsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/student')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'student', N'http://ed-fi.org/ods/identity/claims/student',
-@peopleResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentAcademicRecord', N'http://ed-fi.org/ods/identity/claims/studentAcademicRecord',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentAssessment')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentAssessment', N'http://ed-fi.org/ods/identity/claims/studentAssessment',
-@assessmentMetadataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentAssessmentEducationOrganizationAssociation', N'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentCharacteristicDescriptor', N'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentCohortAssociation', N'http://ed-fi.org/ods/identity/claims/studentCohortAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentCompetencyObjective', N'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentContactAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentContactAssociation', N'http://ed-fi.org/ods/identity/claims/studentContactAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentCTEProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentDisciplineIncidentBehaviorAssociation', N'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentDisciplineIncidentNonOffenderAssociation', N'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentEducationOrganizationAssociation', N'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentEducationOrganizationResponsibilityAssociation', N'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentGradebookEntry', N'http://ed-fi.org/ods/identity/claims/studentGradebookEntry',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentHealth')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentHealth', N'http://ed-fi.org/ods/identity/claims/studentHealth',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentHomelessProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentIdentificationSystemDescriptor', N'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentInterventionAssociation', N'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentInterventionAttendanceEvent', N'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentLanguageInstructionProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentMigrantEducationProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentNeglectedOrDelinquentProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentParticipationCodeDescriptor', N'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentProgramAttendanceEvent', N'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentProgramEvaluation', N'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSchoolAssociation', N'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation',
-@primaryRelationshipsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSchoolAttendanceEvent', N'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSchoolFoodServiceProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSectionAssociation', N'http://ed-fi.org/ods/identity/claims/studentSectionAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSectionAttendanceEvent', N'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSpecialEducationProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentSpecialEducationProgramEligibilityAssociation', N'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentTitleIPartAProgramAssociation', N'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/studentTransportation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'studentTransportation', N'http://ed-fi.org/ods/identity/claims/studentTransportation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'submissionStatusDescriptor', N'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'supporterMilitaryConnectionDescriptor', N'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/survey')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'survey', N'http://ed-fi.org/ods/identity/claims/survey',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyCategoryDescriptor', N'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor',
-@systemDescriptorsResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyCourseAssociation', N'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor')
+IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor')
BEGIN
INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
@@ -2878,105 +1798,6 @@ BEGIN
END
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyProgramAssociation', N'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyQuestion')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyQuestion', N'http://ed-fi.org/ods/identity/claims/surveyQuestion',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyQuestionResponse', N'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyResponse')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyResponse', N'http://ed-fi.org/ods/identity/claims/surveyResponse',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyResponseEducationOrganizationTargetAssociation', N'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveyResponseStaffTargetAssociation', N'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveySection')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveySection', N'http://ed-fi.org/ods/identity/claims/surveySection',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveySectionAssociation', N'http://ed-fi.org/ods/identity/claims/surveySectionAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveySectionResponse')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveySectionResponse', N'http://ed-fi.org/ods/identity/claims/surveySectionResponse',
-@surveyDomainResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveySectionResponseEducationOrganizationTargetAssociation', N'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'surveySectionResponseStaffTargetAssociation', N'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation',
-@relationshipBasedDataResourceClaimId);
-
-END
-
IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor')
BEGIN
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_PgSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_PgSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
index 173f75e2f3..5e8ba8c82a 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_PgSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/Approval/5.1.0/DataStandard_510_ApprovalTests.Verify.Standard_Std_5.1.0_Artifacts_PgSql_Data_Security_0002-ResourceClaimMetadata_generated.approved.sql
@@ -49,21 +49,11 @@ begin
values ('academicSubjectDescriptor', 'http://ed-fi.org/ods/identity/claims/academicSubjectDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='academicWeek') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('academicWeek', 'http://ed-fi.org/ods/identity/claims/academicWeek', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='accommodationDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('accommodationDescriptor', 'http://ed-fi.org/ods/identity/claims/accommodationDescriptor', managedDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='accountabilityRating') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('accountabilityRating', 'http://ed-fi.org/ods/identity/claims/accountabilityRating', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='accountTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('accountTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/accountTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -99,11 +89,6 @@ begin
values ('ancestryEthnicOriginDescriptor', 'http://ed-fi.org/ods/identity/claims/ancestryEthnicOriginDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assessment') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('assessment', 'http://ed-fi.org/ods/identity/claims/assessment', assessmentMetadataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assessmentCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('assessmentCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentCategoryDescriptor', systemDescriptorsResourceClaimId);
@@ -114,11 +99,6 @@ begin
values ('assessmentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentIdentificationSystemDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assessmentItem') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('assessmentItem', 'http://ed-fi.org/ods/identity/claims/assessmentItem', assessmentMetadataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assessmentItemCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('assessmentItemCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentItemCategoryDescriptor', systemDescriptorsResourceClaimId);
@@ -139,11 +119,6 @@ begin
values ('assessmentReportingMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/assessmentReportingMethodDescriptor', managedDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assessmentScoreRangeLearningStandard') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('assessmentScoreRangeLearningStandard', 'http://ed-fi.org/ods/identity/claims/assessmentScoreRangeLearningStandard', assessmentMetadataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='assignmentLateStatusDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('assignmentLateStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/assignmentLateStatusDescriptor', systemDescriptorsResourceClaimId);
@@ -159,11 +134,6 @@ begin
values ('attendanceEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/attendanceEventCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='balanceSheetDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('balanceSheetDimension', 'http://ed-fi.org/ods/identity/claims/balanceSheetDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='barrierToInternetAccessInResidenceDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('barrierToInternetAccessInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/barrierToInternetAccessInResidenceDescriptor', systemDescriptorsResourceClaimId);
@@ -174,26 +144,11 @@ begin
values ('behaviorDescriptor', 'http://ed-fi.org/ods/identity/claims/behaviorDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='bellSchedule') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('bellSchedule', 'http://ed-fi.org/ods/identity/claims/bellSchedule', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='busRouteDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('busRouteDescriptor', 'http://ed-fi.org/ods/identity/claims/busRouteDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='calendar') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('calendar', 'http://ed-fi.org/ods/identity/claims/calendar', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='calendarDate') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('calendarDate', 'http://ed-fi.org/ods/identity/claims/calendarDate', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='calendarEventDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('calendarEventDescriptor', 'http://ed-fi.org/ods/identity/claims/calendarEventDescriptor', systemDescriptorsResourceClaimId);
@@ -219,31 +174,16 @@ begin
values ('charterStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/charterStatusDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='chartOfAccount') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('chartOfAccount', 'http://ed-fi.org/ods/identity/claims/chartOfAccount', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='citizenshipStatusDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('citizenshipStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/citizenshipStatusDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='classPeriod') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('classPeriod', 'http://ed-fi.org/ods/identity/claims/classPeriod', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='classroomPositionDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('classroomPositionDescriptor', 'http://ed-fi.org/ods/identity/claims/classroomPositionDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='cohort') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('cohort', 'http://ed-fi.org/ods/identity/claims/cohort', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='cohortScopeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('cohortScopeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortScopeDescriptor', systemDescriptorsResourceClaimId);
@@ -259,36 +199,11 @@ begin
values ('cohortYearTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/cohortYearTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='communityOrganization') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('communityOrganization', 'http://ed-fi.org/ods/identity/claims/communityOrganization', educationOrganizationsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='communityProvider') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('communityProvider', 'http://ed-fi.org/ods/identity/claims/communityProvider', educationOrganizationsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='communityProviderLicense') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('communityProviderLicense', 'http://ed-fi.org/ods/identity/claims/communityProviderLicense', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='competencyLevelDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('competencyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/competencyLevelDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='competencyObjective') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('competencyObjective', 'http://ed-fi.org/ods/identity/claims/competencyObjective', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='contact') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('contact', 'http://ed-fi.org/ods/identity/claims/contact', peopleResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='contactTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('contactTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/contactTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -314,11 +229,6 @@ begin
values ('countryDescriptor', 'http://ed-fi.org/ods/identity/claims/countryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='course') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('course', 'http://ed-fi.org/ods/identity/claims/course', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='courseAttemptResultDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('courseAttemptResultDescriptor', 'http://ed-fi.org/ods/identity/claims/courseAttemptResultDescriptor', systemDescriptorsResourceClaimId);
@@ -344,26 +254,11 @@ begin
values ('courseLevelCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/courseLevelCharacteristicDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='courseOffering') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('courseOffering', 'http://ed-fi.org/ods/identity/claims/courseOffering', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='courseRepeatCodeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('courseRepeatCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/courseRepeatCodeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='courseTranscript') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('courseTranscript', 'http://ed-fi.org/ods/identity/claims/courseTranscript', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='credential') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('credential', 'http://ed-fi.org/ods/identity/claims/credential', educationStandardsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='credentialFieldDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('credentialFieldDescriptor', 'http://ed-fi.org/ods/identity/claims/credentialFieldDescriptor', systemDescriptorsResourceClaimId);
@@ -384,11 +279,6 @@ begin
values ('creditTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/creditTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='crisisEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('crisisEvent', 'http://ed-fi.org/ods/identity/claims/crisisEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='crisisTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('crisisTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/crisisTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -409,11 +299,6 @@ begin
values ('deliveryMethodDescriptor', 'http://ed-fi.org/ods/identity/claims/deliveryMethodDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='descriptorMapping') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('descriptorMapping', 'http://ed-fi.org/ods/identity/claims/descriptorMapping', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='diagnosisDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('diagnosisDescriptor', 'http://ed-fi.org/ods/identity/claims/diagnosisDescriptor', systemDescriptorsResourceClaimId);
@@ -444,11 +329,6 @@ begin
values ('disabilityDeterminationSourceTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/disabilityDeterminationSourceTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='disciplineAction') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('disciplineAction', 'http://ed-fi.org/ods/identity/claims/disciplineAction', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='disciplineActionLengthDifferenceReasonDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('disciplineActionLengthDifferenceReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineActionLengthDifferenceReasonDescriptor', systemDescriptorsResourceClaimId);
@@ -459,11 +339,6 @@ begin
values ('disciplineDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='disciplineIncident') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('disciplineIncident', 'http://ed-fi.org/ods/identity/claims/disciplineIncident', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='disciplineIncidentParticipationCodeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('disciplineIncidentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/disciplineIncidentParticipationCodeDescriptor', systemDescriptorsResourceClaimId);
@@ -479,11 +354,6 @@ begin
values ('educationalEnvironmentDescriptor', 'http://ed-fi.org/ods/identity/claims/educationalEnvironmentDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationContent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationContent', 'http://ed-fi.org/ods/identity/claims/educationContent', null);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationOrganizationAssociationTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('educationOrganizationAssociationTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationAssociationTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -499,36 +369,11 @@ begin
values ('educationOrganizationIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/educationOrganizationIdentificationSystemDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationOrganizationInterventionPrescriptionAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationOrganizationInterventionPrescriptionAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationInterventionPrescriptionAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationOrganizationNetwork') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationOrganizationNetwork', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetwork', educationOrganizationsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationOrganizationNetworkAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationOrganizationNetworkAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationNetworkAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationOrganizationPeerAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationOrganizationPeerAssociation', 'http://ed-fi.org/ods/identity/claims/educationOrganizationPeerAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationPlanDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('educationPlanDescriptor', 'http://ed-fi.org/ods/identity/claims/educationPlanDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='educationServiceCenter') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('educationServiceCenter', 'http://ed-fi.org/ods/identity/claims/educationServiceCenter', educationOrganizationsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='electronicMailTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('electronicMailTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/electronicMailTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -569,11 +414,6 @@ begin
values ('evaluationDelayReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/evaluationDelayReasonDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='evaluationRubricDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('evaluationRubricDimension', 'http://ed-fi.org/ods/identity/claims/evaluationRubricDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='eventCircumstanceDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('eventCircumstanceDescriptor', 'http://ed-fi.org/ods/identity/claims/eventCircumstanceDescriptor', systemDescriptorsResourceClaimId);
@@ -584,36 +424,11 @@ begin
values ('exitWithdrawTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/exitWithdrawTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='feederSchoolAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('feederSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/feederSchoolAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='financialCollectionDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('financialCollectionDescriptor', 'http://ed-fi.org/ods/identity/claims/financialCollectionDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='functionDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('functionDimension', 'http://ed-fi.org/ods/identity/claims/functionDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='fundDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('fundDimension', 'http://ed-fi.org/ods/identity/claims/fundDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='grade') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('grade', 'http://ed-fi.org/ods/identity/claims/grade', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='gradebookEntry') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('gradebookEntry', 'http://ed-fi.org/ods/identity/claims/gradebookEntry', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='gradebookEntryTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('gradebookEntryTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradebookEntryTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -634,21 +449,11 @@ begin
values ('gradeTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/gradeTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='gradingPeriod') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('gradingPeriod', 'http://ed-fi.org/ods/identity/claims/gradingPeriod', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='gradingPeriodDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('gradingPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/gradingPeriodDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='graduationPlan') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('graduationPlan', 'http://ed-fi.org/ods/identity/claims/graduationPlan', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='graduationPlanTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('graduationPlanTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/graduationPlanTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -729,11 +534,6 @@ begin
values ('internetPerformanceInResidenceDescriptor', 'http://ed-fi.org/ods/identity/claims/internetPerformanceInResidenceDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='intervention') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('intervention', 'http://ed-fi.org/ods/identity/claims/intervention', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='interventionClassDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('interventionClassDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionClassDescriptor', systemDescriptorsResourceClaimId);
@@ -744,16 +544,6 @@ begin
values ('interventionEffectivenessRatingDescriptor', 'http://ed-fi.org/ods/identity/claims/interventionEffectivenessRatingDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='interventionPrescription') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('interventionPrescription', 'http://ed-fi.org/ods/identity/claims/interventionPrescription', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='interventionStudy') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('interventionStudy', 'http://ed-fi.org/ods/identity/claims/interventionStudy', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='languageDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('languageDescriptor', 'http://ed-fi.org/ods/identity/claims/languageDescriptor', systemDescriptorsResourceClaimId);
@@ -769,21 +559,11 @@ begin
values ('languageUseDescriptor', 'http://ed-fi.org/ods/identity/claims/languageUseDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='learningStandard') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('learningStandard', 'http://ed-fi.org/ods/identity/claims/learningStandard', educationStandardsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='learningStandardCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('learningStandardCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='learningStandardEquivalenceAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('learningStandardEquivalenceAssociation', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceAssociation', educationStandardsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='learningStandardEquivalenceStrengthDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('learningStandardEquivalenceStrengthDescriptor', 'http://ed-fi.org/ods/identity/claims/learningStandardEquivalenceStrengthDescriptor', systemDescriptorsResourceClaimId);
@@ -814,56 +594,16 @@ begin
values ('limitedEnglishProficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/limitedEnglishProficiencyDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localAccount') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localAccount', 'http://ed-fi.org/ods/identity/claims/localAccount', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localActual') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localActual', 'http://ed-fi.org/ods/identity/claims/localActual', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localBudget') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localBudget', 'http://ed-fi.org/ods/identity/claims/localBudget', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localContractedStaff') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localContractedStaff', 'http://ed-fi.org/ods/identity/claims/localContractedStaff', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('localeDescriptor', 'http://ed-fi.org/ods/identity/claims/localeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localEducationAgency') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localEducationAgency', 'http://ed-fi.org/ods/identity/claims/localEducationAgency', educationOrganizationsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localEducationAgencyCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('localEducationAgencyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/localEducationAgencyCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localEncumbrance') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localEncumbrance', 'http://ed-fi.org/ods/identity/claims/localEncumbrance', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='localPayroll') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('localPayroll', 'http://ed-fi.org/ods/identity/claims/localPayroll', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='location') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('location', 'http://ed-fi.org/ods/identity/claims/location', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='magnetSpecialProgramEmphasisSchoolDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('magnetSpecialProgramEmphasisSchoolDescriptor', 'http://ed-fi.org/ods/identity/claims/magnetSpecialProgramEmphasisSchoolDescriptor', systemDescriptorsResourceClaimId);
@@ -914,36 +654,11 @@ begin
values ('nonMedicalImmunizationExemptionDescriptor', 'http://ed-fi.org/ods/identity/claims/nonMedicalImmunizationExemptionDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='objectDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('objectDimension', 'http://ed-fi.org/ods/identity/claims/objectDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='objectiveAssessment') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('objectiveAssessment', 'http://ed-fi.org/ods/identity/claims/objectiveAssessment', assessmentMetadataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='openStaffPosition') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('openStaffPosition', 'http://ed-fi.org/ods/identity/claims/openStaffPosition', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='operationalStatusDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('operationalStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/operationalStatusDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='operationalUnitDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('operationalUnitDimension', 'http://ed-fi.org/ods/identity/claims/operationalUnitDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='organizationDepartment') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('organizationDepartment', 'http://ed-fi.org/ods/identity/claims/organizationDepartment', educationOrganizationsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='otherNameTypeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('otherNameTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/otherNameTypeDescriptor', systemDescriptorsResourceClaimId);
@@ -969,11 +684,6 @@ begin
values ('performanceLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/performanceLevelDescriptor', managedDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='person') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('person', 'http://ed-fi.org/ods/identity/claims/person', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='personalInformationVerificationDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('personalInformationVerificationDescriptor', 'http://ed-fi.org/ods/identity/claims/personalInformationVerificationDescriptor', systemDescriptorsResourceClaimId);
@@ -994,21 +704,11 @@ begin
values ('postingResultDescriptor', 'http://ed-fi.org/ods/identity/claims/postingResultDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='postSecondaryEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('postSecondaryEvent', 'http://ed-fi.org/ods/identity/claims/postSecondaryEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='postSecondaryEventCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('postSecondaryEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryEventCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='postSecondaryInstitution') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('postSecondaryInstitution', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitution', educationOrganizationsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='postSecondaryInstitutionLevelDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('postSecondaryInstitutionLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/postSecondaryInstitutionLevelDescriptor', systemDescriptorsResourceClaimId);
@@ -1034,11 +734,6 @@ begin
values ('proficiencyDescriptor', 'http://ed-fi.org/ods/identity/claims/proficiencyDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='program') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('program', 'http://ed-fi.org/ods/identity/claims/program', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programAssignmentDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('programAssignmentDescriptor', 'http://ed-fi.org/ods/identity/claims/programAssignmentDescriptor', systemDescriptorsResourceClaimId);
@@ -1049,26 +744,6 @@ begin
values ('programCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/programCharacteristicDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('programDimension', 'http://ed-fi.org/ods/identity/claims/programDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programEvaluation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('programEvaluation', 'http://ed-fi.org/ods/identity/claims/programEvaluation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programEvaluationElement') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('programEvaluationElement', 'http://ed-fi.org/ods/identity/claims/programEvaluationElement', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programEvaluationObjective') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('programEvaluationObjective', 'http://ed-fi.org/ods/identity/claims/programEvaluationObjective', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='programEvaluationPeriodDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('programEvaluationPeriodDescriptor', 'http://ed-fi.org/ods/identity/claims/programEvaluationPeriodDescriptor', systemDescriptorsResourceClaimId);
@@ -1099,11 +774,6 @@ begin
values ('progressLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/progressLevelDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='projectDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('projectDimension', 'http://ed-fi.org/ods/identity/claims/projectDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='providerCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('providerCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/providerCategoryDescriptor', systemDescriptorsResourceClaimId);
@@ -1164,11 +834,6 @@ begin
values ('repeatIdentifierDescriptor', 'http://ed-fi.org/ods/identity/claims/repeatIdentifierDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='reportCard') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('reportCard', 'http://ed-fi.org/ods/identity/claims/reportCard', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='reporterDescriptionDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('reporterDescriptionDescriptor', 'http://ed-fi.org/ods/identity/claims/reporterDescriptionDescriptor', systemDescriptorsResourceClaimId);
@@ -1194,11 +859,6 @@ begin
values ('responsibilityDescriptor', 'http://ed-fi.org/ods/identity/claims/responsibilityDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='restraintEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('restraintEvent', 'http://ed-fi.org/ods/identity/claims/restraintEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='restraintEventReasonDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('restraintEventReasonDescriptor', 'http://ed-fi.org/ods/identity/claims/restraintEventReasonDescriptor', systemDescriptorsResourceClaimId);
@@ -1214,11 +874,6 @@ begin
values ('retestIndicatorDescriptor', 'http://ed-fi.org/ods/identity/claims/retestIndicatorDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='school') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('school', 'http://ed-fi.org/ods/identity/claims/school', educationOrganizationsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='schoolCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('schoolCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolCategoryDescriptor', systemDescriptorsResourceClaimId);
@@ -1244,21 +899,6 @@ begin
values ('schoolTypeDescriptor', 'http://ed-fi.org/ods/identity/claims/schoolTypeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='schoolYearType') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('schoolYearType', 'http://ed-fi.org/ods/identity/claims/schoolYearType', typesResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='section') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('section', 'http://ed-fi.org/ods/identity/claims/section', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='sectionAttendanceTakenEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('sectionAttendanceTakenEvent', 'http://ed-fi.org/ods/identity/claims/sectionAttendanceTakenEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='sectionCharacteristicDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('sectionCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/sectionCharacteristicDescriptor', systemDescriptorsResourceClaimId);
@@ -1284,21 +924,11 @@ begin
values ('serviceDescriptor', 'http://ed-fi.org/ods/identity/claims/serviceDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='session') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('session', 'http://ed-fi.org/ods/identity/claims/session', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='sexDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('sexDescriptor', 'http://ed-fi.org/ods/identity/claims/sexDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='sourceDimension') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('sourceDimension', 'http://ed-fi.org/ods/identity/claims/sourceDimension', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='sourceSystemDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('sourceSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/sourceSystemDescriptor', systemDescriptorsResourceClaimId);
@@ -1319,261 +949,41 @@ begin
values ('specialEducationSettingDescriptor', 'http://ed-fi.org/ods/identity/claims/specialEducationSettingDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staff') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staff', 'http://ed-fi.org/ods/identity/claims/staff', peopleResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffAbsenceEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffAbsenceEvent', 'http://ed-fi.org/ods/identity/claims/staffAbsenceEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffClassificationDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('staffClassificationDescriptor', 'http://ed-fi.org/ods/identity/claims/staffClassificationDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffCohortAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffCohortAssociation', 'http://ed-fi.org/ods/identity/claims/staffCohortAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffDisciplineIncidentAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffDisciplineIncidentAssociation', 'http://ed-fi.org/ods/identity/claims/staffDisciplineIncidentAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffEducationOrganizationAssignmentAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffEducationOrganizationAssignmentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationAssignmentAssociation', primaryRelationshipsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffEducationOrganizationContactAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffEducationOrganizationContactAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationContactAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffEducationOrganizationEmploymentAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffEducationOrganizationEmploymentAssociation', 'http://ed-fi.org/ods/identity/claims/staffEducationOrganizationEmploymentAssociation', primaryRelationshipsResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffIdentificationSystemDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('staffIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/staffIdentificationSystemDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffLeave') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffLeave', 'http://ed-fi.org/ods/identity/claims/staffLeave', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffLeaveEventCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('staffLeaveEventCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/staffLeaveEventCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffProgramAssociation', 'http://ed-fi.org/ods/identity/claims/staffProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffSchoolAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/staffSchoolAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='staffSectionAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('staffSectionAssociation', 'http://ed-fi.org/ods/identity/claims/staffSectionAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='stateAbbreviationDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('stateAbbreviationDescriptor', 'http://ed-fi.org/ods/identity/claims/stateAbbreviationDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='stateEducationAgency') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('stateEducationAgency', 'http://ed-fi.org/ods/identity/claims/stateEducationAgency', educationOrganizationsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='student') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('student', 'http://ed-fi.org/ods/identity/claims/student', peopleResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentAcademicRecord') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentAcademicRecord', 'http://ed-fi.org/ods/identity/claims/studentAcademicRecord', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentAssessment') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentAssessment', 'http://ed-fi.org/ods/identity/claims/studentAssessment', assessmentMetadataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentAssessmentEducationOrganizationAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentAssessmentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentAssessmentEducationOrganizationAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentCharacteristicDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('studentCharacteristicDescriptor', 'http://ed-fi.org/ods/identity/claims/studentCharacteristicDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentCohortAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentCohortAssociation', 'http://ed-fi.org/ods/identity/claims/studentCohortAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentCompetencyObjective') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentCompetencyObjective', 'http://ed-fi.org/ods/identity/claims/studentCompetencyObjective', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentContactAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentContactAssociation', 'http://ed-fi.org/ods/identity/claims/studentContactAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentCTEProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentCTEProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentCTEProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentDisciplineIncidentBehaviorAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentDisciplineIncidentBehaviorAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentBehaviorAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentDisciplineIncidentNonOffenderAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentDisciplineIncidentNonOffenderAssociation', 'http://ed-fi.org/ods/identity/claims/studentDisciplineIncidentNonOffenderAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentEducationOrganizationAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentEducationOrganizationAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentEducationOrganizationResponsibilityAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentEducationOrganizationResponsibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationResponsibilityAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentGradebookEntry') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentGradebookEntry', 'http://ed-fi.org/ods/identity/claims/studentGradebookEntry', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentHealth') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentHealth', 'http://ed-fi.org/ods/identity/claims/studentHealth', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentHomelessProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentHomelessProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentHomelessProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentIdentificationSystemDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('studentIdentificationSystemDescriptor', 'http://ed-fi.org/ods/identity/claims/studentIdentificationSystemDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentInterventionAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentInterventionAssociation', 'http://ed-fi.org/ods/identity/claims/studentInterventionAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentInterventionAttendanceEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentInterventionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentInterventionAttendanceEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentLanguageInstructionProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentLanguageInstructionProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentLanguageInstructionProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentMigrantEducationProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentMigrantEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentMigrantEducationProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentNeglectedOrDelinquentProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentNeglectedOrDelinquentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentNeglectedOrDelinquentProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentParticipationCodeDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('studentParticipationCodeDescriptor', 'http://ed-fi.org/ods/identity/claims/studentParticipationCodeDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentProgramAttendanceEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentProgramAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentProgramAttendanceEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentProgramEvaluation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentProgramEvaluation', 'http://ed-fi.org/ods/identity/claims/studentProgramEvaluation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSchoolAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSchoolAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolAssociation', primaryRelationshipsResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSchoolAttendanceEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSchoolAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSchoolAttendanceEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSchoolFoodServiceProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSchoolFoodServiceProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSchoolFoodServiceProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSectionAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSectionAssociation', 'http://ed-fi.org/ods/identity/claims/studentSectionAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSectionAttendanceEvent') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSectionAttendanceEvent', 'http://ed-fi.org/ods/identity/claims/studentSectionAttendanceEvent', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSpecialEducationProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSpecialEducationProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentSpecialEducationProgramEligibilityAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentSpecialEducationProgramEligibilityAssociation', 'http://ed-fi.org/ods/identity/claims/studentSpecialEducationProgramEligibilityAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentTitleIPartAProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentTitleIPartAProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentTitleIPartAProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='studentTransportation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('studentTransportation', 'http://ed-fi.org/ods/identity/claims/studentTransportation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='submissionStatusDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('submissionStatusDescriptor', 'http://ed-fi.org/ods/identity/claims/submissionStatusDescriptor', systemDescriptorsResourceClaimId);
@@ -1584,81 +994,16 @@ begin
values ('supporterMilitaryConnectionDescriptor', 'http://ed-fi.org/ods/identity/claims/supporterMilitaryConnectionDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='survey') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('survey', 'http://ed-fi.org/ods/identity/claims/survey', surveyDomainResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyCategoryDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('surveyCategoryDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyCategoryDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyCourseAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyCourseAssociation', 'http://ed-fi.org/ods/identity/claims/surveyCourseAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyLevelDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('surveyLevelDescriptor', 'http://ed-fi.org/ods/identity/claims/surveyLevelDescriptor', systemDescriptorsResourceClaimId);
END IF;
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyProgramAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyProgramAssociation', 'http://ed-fi.org/ods/identity/claims/surveyProgramAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyQuestion') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyQuestion', 'http://ed-fi.org/ods/identity/claims/surveyQuestion', surveyDomainResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyQuestionResponse') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyQuestionResponse', 'http://ed-fi.org/ods/identity/claims/surveyQuestionResponse', surveyDomainResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyResponse') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyResponse', 'http://ed-fi.org/ods/identity/claims/surveyResponse', surveyDomainResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyResponseEducationOrganizationTargetAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseEducationOrganizationTargetAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveyResponseStaffTargetAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveyResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveyResponseStaffTargetAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveySection') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveySection', 'http://ed-fi.org/ods/identity/claims/surveySection', surveyDomainResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveySectionAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveySectionAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveySectionResponse') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveySectionResponse', 'http://ed-fi.org/ods/identity/claims/surveySectionResponse', surveyDomainResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveySectionResponseEducationOrganizationTargetAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveySectionResponseEducationOrganizationTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseEducationOrganizationTargetAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='surveySectionResponseStaffTargetAssociation') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('surveySectionResponseStaffTargetAssociation', 'http://ed-fi.org/ods/identity/claims/surveySectionResponseStaffTargetAssociation', relationshipBasedDataResourceClaimId);
- END IF;
-
IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='teachingCredentialBasisDescriptor') THEN
insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
values ('teachingCredentialBasisDescriptor', 'http://ed-fi.org/ods/identity/claims/teachingCredentialBasisDescriptor', systemDescriptorsResourceClaimId);
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/IntegrationTests/Providers/AssemblyDataProviderTests.cs b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/IntegrationTests/Providers/AssemblyDataProviderTests.cs
index 4183600685..a9208774a3 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/IntegrationTests/Providers/AssemblyDataProviderTests.cs
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen.Tests/IntegrationTests/Providers/AssemblyDataProviderTests.cs
@@ -43,8 +43,7 @@ public void Should_have_correct_assemblies_for_processing()
{
var expected = new List
{
- "EdFi.Ods.Standard",
- "ODS Database Specific",
+ "EdFi.Ods.Standard"
};
_assemblyData.Select(x => x.AssemblyName).ForEach(x => expected.ShouldContain(x));
@@ -85,7 +84,6 @@ public void Should_have_correct_assemblies_for_processing()
"EdFi.Ods.Extensions.Sample",
"EdFi.Ods.Extensions.TPDM",
"EdFi.Ods.Standard",
- "ODS Database Specific",
"EdFi.Ods.Extensions.SampleAlternativeEducationProgram",
"EdFi.Ods.Extensions.SampleStudentTranscript",
};
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Generators/ResourceClaimMetadata.cs b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Generators/ResourceClaimMetadata.cs
deleted file mode 100644
index f3928e78ac..0000000000
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Generators/ResourceClaimMetadata.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-// 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.CodeGen.Models;
-using EdFi.Ods.Common.Models.Domain;
-using EdFi.Ods.Common.Specifications;
-
-namespace EdFi.Ods.CodeGen.Generators
-{
- public class ResourceClaimMetadata : GeneratorBase
- {
- private IPersonEntitySpecification _personEntitySpecification;
- private IEducationOrganizationEntitySpecification _educationOrganizationEntitySpecification;
-
- protected override object Build()
- {
- var domainModel = TemplateContext.DomainModelProvider.GetDomainModel();
-
- _personEntitySpecification =
- new PersonEntitySpecification(
- new PersonTypesProvider(
- new SuppliedDomainModelProvider(domainModel)));
-
- _educationOrganizationEntitySpecification =
- new EducationOrganizationEntitySpecification(
- new EducationOrganizationTypesProvider(
- new SuppliedDomainModelProvider(domainModel)));
-
- var orderedAggregates = domainModel
- .Entities
- .Where(x => x.IsAggregateRoot && !x.IsAbstract)
- .OrderBy(x => x.FullName.Name)
- .Select(
- x => new
- {
- DisplayName = x.Name.ToCamelCase(),
- ResourceName = x.Name.ToCamelCase(),
- ParentResourceName = GetParentResource(x),
- HasParent = GetParentResource(x) != null
- })
- .ToList();
-
- return new {Aggregates = orderedAggregates};
- }
-
- private string GetParentResource(Entity entity)
- {
- var resourceName = entity.Name;
-
- if (resourceName.EndsWith("type", StringComparison.InvariantCultureIgnoreCase))
- {
- return "types";
- }
-
- if (DescriptorEntitySpecification.IsEdFiDescriptorEntity(resourceName))
- {
- return ManagedDescriptorSpecification.IsEdFiManagedDescriptor(resourceName)
- ? "managedDescriptors"
- : "systemDescriptors";
- }
-
- if (_educationOrganizationEntitySpecification.IsEducationOrganizationEntity(resourceName))
- {
- return "educationOrganizations";
- }
-
- if (_personEntitySpecification.IsPersonEntity(resourceName))
- {
- return "people";
- }
-
- if (AssessmentSpecification.IsAssessmentEntity(resourceName))
- {
- return "assessmentMetadata";
- }
-
- if (resourceName.Equals("educationContent", StringComparison.InvariantCultureIgnoreCase))
- {
- return null;
- }
-
- if (EducationStandardSpecification.IsEducationStandardEntity(resourceName))
- {
- return "educationStandards";
- }
-
- if (PrimaryRelationshipEntitySpecification.IsPrimaryRelationshipEntity(resourceName))
- {
- return "primaryRelationships";
- }
-
- if (SurveySpecification.IsSurveyEntity(resourceName))
- {
- return "surveyDomain";
- }
-
- return "relationshipBasedData";
- }
- }
-}
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Modules/ProvidersModule.cs b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Modules/ProvidersModule.cs
index 03bfdeaec3..5a1d1144db 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Modules/ProvidersModule.cs
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Modules/ProvidersModule.cs
@@ -32,9 +32,6 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType()
.As();
- builder.RegisterType()
- .As();
-
builder.RegisterType()
.As()
.PreserveExistingDefaults();
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.mustache b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.mustache
deleted file mode 100644
index 93245fb5e2..0000000000
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.mustache
+++ /dev/null
@@ -1,751 +0,0 @@
-DECLARE @ClaimSetId INT;
-DECLARE @AuthorizationStrategyId INT;
-
-DECLARE @peopleResourceClaimId INT;
-DECLARE @relationshipBasedDataResourceClaimId INT;
-DECLARE @assessmentMetadataResourceClaimId INT;
-DECLARE @educationStandardsResourceClaimId INT;
-DECLARE @primaryRelationshipsResourceClaimId INT;
-DECLARE @educationOrganizationsResourceClaimId INT;
-DECLARE @typesResourceClaimId INT;
-DECLARE @systemDescriptorsResourceClaimId INT;
-DECLARE @managedDescriptorsResourceClaimId INT;
-DECLARE @identityResourceClaimId INT;
-DECLARE @surveyDomainResourceClaimId INT;
-
-SELECT @typesResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/edFiTypes');
-
-SELECT @systemDescriptorsResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/systemDescriptors');
-
-SELECT @managedDescriptorsResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/managedDescriptors');
-
-SELECT @educationOrganizationsResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/educationOrganizations');
-
-SELECT @peopleResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/people');
-
-SELECT @relationshipBasedDataResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData');
-
-SELECT @assessmentMetadataResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/assessmentMetadata');
-
-SELECT @identityResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/identity');
-
-SELECT @educationStandardsResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/educationStandards');
-
-SELECT @primaryRelationshipsResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/primaryRelationships');
-
-SELECT @surveyDomainResourceClaimId = (SELECT [ResourceClaimId] FROM [dbo].[ResourceClaims]
- WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/domains/surveyDomain');
-
-/* ==================================================================================================================================== */
-
-/* --------------------------------- */
-/* Resource Claims */
-/* --------------------------------- */
-
-{{#Aggregates}}
-IF NOT EXISTS(SELECT 1 FROM [dbo].[ResourceClaims] WHERE [ClaimName] = 'http://ed-fi.org/ods/identity/claims/{{ResourceName}}')
-BEGIN
-
- INSERT [dbo].[ResourceClaims] ([ResourceName], [ClaimName], [ParentResourceClaimId])
- VALUES (N'{{ResourceName}}', N'http://ed-fi.org/ods/identity/claims/{{ResourceName}}',
-{{#HasParent}}@{{ParentResourceName}}ResourceClaimId{{/HasParent}}{{^HasParent}}NULL{{/HasParent}});
-
-END
-
-{{/Aggregates}}
-/* ==================================================================================================================================== */
-
-/* --------------------------------------------------- */
-/* ClaimSetResourceClaimActions */
-/* ---------------------------------------------------- */
-
-/* SIS Vendors Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'SIS Vendor');
-
-WITH SisVendorClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read','Update','Delete')) AS ac
- WHERE ResourceName IN ('people'
- , 'relationshipBasedData'
- , 'assessmentMetadata'
- , 'managedDescriptors'
- , 'primaryRelationships'
- , 'educationStandards'
- , 'educationContent')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('people'
- , 'relationshipBasedData'
- , 'assessmentMetadata'
- , 'managedDescriptors'
- , 'primaryRelationships'
- , 'educationStandards'
- , 'educationContent')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM SisVendorClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* EdFi Sandbox Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Ed-Fi Sandbox');
-
-WITH EdFiSandboxClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('types', 'identity')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create', 'Update')) AS ac
- WHERE ResourceName IN ('identity')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read','Update','Delete')) AS ac
- WHERE ResourceName IN ('systemDescriptors', 'educationOrganizations', 'people', 'relationshipBasedData',
- 'assessmentMetadata', 'managedDescriptors', 'primaryRelationships', 'educationStandards',
- 'educationContent', 'surveyDomain')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('systemDescriptors', 'educationOrganizations', 'people', 'relationshipBasedData',
- 'assessmentMetadata', 'managedDescriptors', 'primaryRelationships', 'educationStandards',
- 'educationContent', 'surveyDomain')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM EdFiSandboxClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* EdFi Sandbox Claims with Overrides */
-
-WITH EdFiSandboxClaimsWithOverrides (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create','Read','Update','Delete')) AS ac
- WHERE ResourceName IN ('communityProviderLicense')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM EdFiSandboxClaimsWithOverrides claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* Roster Vendor Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Roster Vendor');
-
-WITH RosterVendorClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('educationOrganizations', 'section', 'student', 'staff', 'courseOffering',
- 'session', 'classPeriod', 'location', 'course', 'staffSectionAssociation',
- 'staffEducationOrganizationAssignmentAssociation', 'studentSectionAssociation', 'studentSchoolAssociation')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM RosterVendorClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* Assessment Vendor Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Assessment Vendor');
-
-WITH AssessmentVendorClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create','Read','Update','Delete')) AS ac
- WHERE ResourceName IN ('academicSubjectDescriptor', 'assessmentMetadata', 'learningObjective', 'managedDescriptors', 'learningStandard')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('student', 'systemDescriptors', 'types')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM AssessmentVendorClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* Assessment Read Resource Claims */
-
-SET @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Assessment Read');
-
-WITH AssessmentReadResourceClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('assessmentMetadata', 'learningObjective', 'learningStandard', 'student')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM AssessmentReadResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* Bootstrap Descriptors and EdOrgs Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Bootstrap Descriptors and EdOrgs');
-
-WITH BootstrapDescriptorsAndEdOrgsClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN (
- 'systemDescriptors',
- 'managedDescriptors',
- 'educationOrganizations',
- -- from Interchange-Standards.xml
- 'learningObjective',
- 'learningStandard',
- 'learningStandardEquivalenceAssociation',
- -- from Interchange-EducationOrganization.xml
- 'accountabilityRating',
- 'classPeriod',
- 'communityOrganization',
- 'communityProvider',
- 'communityProviderLicense',
- 'course',
- 'educationOrganizationNetwork',
- 'educationOrganizationNetworkAssociation',
- 'educationOrganizationPeerAssociation',
- 'educationServiceCenter',
- 'feederSchoolAssociation',
- 'localEducationAgency',
- 'location',
- 'postSecondaryInstitution',
- 'program',
- 'school',
- 'stateEducationAgency')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM BootstrapDescriptorsAndEdOrgsClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* District Hosted SIS Vendor Claims */
-
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'District Hosted SIS Vendor');
-
-WITH DistrictHostedSisVendorClaims (ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride)
-AS
-(
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'localEducationAgency')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Update')) AS ac
- WHERE ResourceName IN ('localEducationAgency')
- UNION
- SELECT ac.ActionId, @ClaimSetId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create','Read','Update','Delete')) AS ac
- WHERE ResourceName IN ('assessmentMetadata'
- , 'educationContent'
- , 'educationStandards'
- , 'managedDescriptors'
- , 'people'
- , 'primaryRelationships'
- , 'relationshipBasedData'
- , 'school'
- , 'organizationDepartment')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActions]
- ([ActionId]
- ,[ClaimSetId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetNameOverride])
-SELECT ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
-FROM DistrictHostedSisVendorClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActions] WHERE ActionId = claims.ActionId AND ClaimSetId = claims.ClaimSetId
- AND ResourceClaimId = claims.ResourceClaimId);
-
-/* ==================================================================================================================================== */
-
-/* --------------------------------- */
-/* ResourceClaimActions */
-/* --------------------------------- */
-
-/* NoFurtherAuthorizationRequired */
-
-WITH NoFurtherAuthorizationRequiredResourceClaims (ActionId, ResourceClaimId, ValidationRuleSetName)
-AS
-(
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'course', 'managedDescriptors',
- 'identity', 'credential', 'person' )
- UNION
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('educationOrganizations', 'credential', 'people', 'identity', 'person')
- UNION
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Update')) AS ac
- WHERE ResourceName IN ('educationOrganizations', 'identity', 'credential', 'person' )
- UNION
- SELECT ac.ActionId, ResourceClaimId, null FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Delete')) AS ac
- WHERE ResourceName IN ('educationOrganizations', 'people', 'credential', 'person')
-)
-INSERT INTO [dbo].[ResourceClaimActions]
- ([ActionId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetName])
-SELECT ActionId, ResourceClaimId, ValidationRuleSetName
-FROM NoFurtherAuthorizationRequiredResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActions] WHERE ActionId = claims.ActionId AND ResourceClaimId = claims.ResourceClaimId);
-
-/* NamespaceBased */
-
-WITH NamespaceBasedResourceClaims (ActionId, ResourceClaimId, ValidationRuleSetName)
-AS
-(
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read')) AS ac
- WHERE ResourceName IN ('assessmentMetadata', 'educationStandards', 'educationContent', 'surveyDomain' )
- UNION
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create', 'Update', 'Delete')) AS ac
- WHERE ResourceName IN ('systemDescriptors', 'managedDescriptors', 'assessmentMetadata',
- 'educationStandards', 'educationContent', 'surveyDomain')
-)
-INSERT INTO [dbo].[ResourceClaimActions]
- ([ActionId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetName])
-SELECT ActionId, ResourceClaimId, ValidationRuleSetName
-FROM NamespaceBasedResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActions] WHERE ActionId = claims.ActionId AND ResourceClaimId = claims.ResourceClaimId);
-
-/* RelationshipsWithEdOrgsAndPeople */
-
-WITH RelationshipsWithEdOrgsAndPeopleResourceClaims (ActionId, ResourceClaimId, ValidationRuleSetName)
-AS
-(
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Read', 'Update')) AS ac
- WHERE ResourceName IN ('primaryRelationships', 'studentParentAssociation', 'people', 'relationshipBasedData', 'organizationDepartment')
- UNION
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('relationshipBasedData', 'organizationDepartment')
- UNION
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Delete')) AS ac
- WHERE ResourceName IN ('relationshipBasedData', 'studentParentAssociation', 'primaryRelationships', 'organizationDepartment')
-)
-INSERT INTO [dbo].[ResourceClaimActions]
- ([ActionId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetName])
-SELECT ActionId, ResourceClaimId, ValidationRuleSetName
-FROM RelationshipsWithEdOrgsAndPeopleResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActions] WHERE ActionId = claims.ActionId AND ResourceClaimId = claims.ResourceClaimId);
-
-/* RelationshipsWithStudentsOnly */
-
-WITH RelationshipsWithStudentsOnlyResourceClaims (ActionId, ResourceClaimId, ValidationRuleSetName)
-AS
-(
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('studentParentAssociation')
-)
-INSERT INTO [dbo].[ResourceClaimActions]
- ([ActionId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetName])
-SELECT ActionId, ResourceClaimId, ValidationRuleSetName
-FROM RelationshipsWithStudentsOnlyResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActions] WHERE ActionId = claims.ActionId AND ResourceClaimId = claims.ResourceClaimId);
-
-/* RelationshipsWithEdOrgsOnly */
-
-WITH RelationshipsWithEdOrgsOnlyResourceClaims (ActionId, ResourceClaimId, ValidationRuleSetName)
-AS
-(
- SELECT ac.ActionId, ResourceClaimId, null
- FROM [dbo].[ResourceClaims]
- CROSS APPLY
- (SELECT ActionId
- FROM [dbo].[Actions]
- WHERE ActionName IN ('Create')) AS ac
- WHERE ResourceName IN ('primaryRelationships')
-)
-INSERT INTO [dbo].[ResourceClaimActions]
- ([ActionId]
- ,[ResourceClaimId]
- ,[ValidationRuleSetName])
-SELECT ActionId, ResourceClaimId, ValidationRuleSetName
-FROM RelationshipsWithEdOrgsOnlyResourceClaims claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActions] WHERE ActionId = claims.ActionId AND ResourceClaimId = claims.ResourceClaimId);
-
-/* ==================================================================================================================================== */
-
-/* ------------------------------------------- */
-/* ResourceClaimActionAuthorizationStrategies */
-/* --------------------------------------------- */
-
-/* NoFurtherAuthorizationRequired */
-
-SELECT @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'NoFurtherAuthorizationRequired');
-
-WITH NoFurtherAuthorizationRequiredAuthorizationStrategies (ResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Read')
- AND RC.ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'course', 'managedDescriptors',
- 'identity', 'credential', 'person')
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Create')
- AND RC.ResourceName IN ('educationOrganizations', 'credential', 'people', 'identity', 'person')
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Update')
- AND RC.ResourceName IN ('educationOrganizations', 'identity', 'credential', 'person' )
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Delete')
- AND RC.ResourceName IN ('educationOrganizations', 'people', 'credential', 'person')
-)
-INSERT INTO [dbo].[ResourceClaimActionAuthorizationStrategies]
- ([ResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ResourceClaimActionId, AuthorizationStrategyId
-FROM NoFurtherAuthorizationRequiredAuthorizationStrategies claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActionAuthorizationStrategies] WHERE ResourceClaimActionId = claims.ResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* NamespaceBased */
-
-SELECT @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'NamespaceBased');
-
-WITH NamespaceBasedAuthorizationStrategies (ResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Read')
- AND RC.ResourceName IN ('assessmentMetadata', 'educationContent', 'surveyDomain' )
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Create', 'Update', 'Delete')
- AND RC.ResourceName IN ('systemDescriptors', 'managedDescriptors', 'assessmentMetadata',
- 'educationStandards', 'educationContent', 'surveyDomain')
-)
-INSERT INTO [dbo].[ResourceClaimActionAuthorizationStrategies]
- ([ResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ResourceClaimActionId, AuthorizationStrategyId
-FROM NamespaceBasedAuthorizationStrategies claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActionAuthorizationStrategies] WHERE ResourceClaimActionId = claims.ResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithEdOrgsAndPeople */
-
-SELECT @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople');
-
-WITH RelationshipsWithEdOrgsAndPeopleAuthorizationStrategies (ResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Read', 'Update')
- AND RC.ResourceName IN ('primaryRelationships', 'studentParentAssociation', 'people', 'relationshipBasedData', 'organizationDepartment')
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Create')
- AND RC.ResourceName IN ('relationshipBasedData', 'organizationDepartment')
- UNION
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Delete')
- AND RC.ResourceName IN ('relationshipBasedData', 'studentParentAssociation', 'primaryRelationships', 'organizationDepartment')
-)
-INSERT INTO [dbo].[ResourceClaimActionAuthorizationStrategies]
- ([ResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ResourceClaimActionId, AuthorizationStrategyId
-FROM RelationshipsWithEdOrgsAndPeopleAuthorizationStrategies claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActionAuthorizationStrategies] WHERE ResourceClaimActionId = claims.ResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithStudentsOnly */
-
-SELECT @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'RelationshipsWithStudentsOnly');
-
-WITH RelationshipsWithStudentsOnlyAuthorizationStrategies (ResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Create')
- AND RC.ResourceName IN ('studentParentAssociation')
-)
-INSERT INTO [dbo].[ResourceClaimActionAuthorizationStrategies]
- ([ResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ResourceClaimActionId, AuthorizationStrategyId
-FROM RelationshipsWithStudentsOnlyAuthorizationStrategies claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActionAuthorizationStrategies] WHERE ResourceClaimActionId = claims.ResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithEdOrgsOnly */
-
-SET @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly');
-
-WITH RelationshipsWithEdOrgsOnlyAuthorizationStrategies (ResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT RCAA.ResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ResourceClaimActions] RCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = RCAA.ActionId
- WHERE A.ActionName IN ('Create')
- AND RC.ResourceName IN ('primaryRelationships')
-)
-INSERT INTO [dbo].[ResourceClaimActionAuthorizationStrategies]
- ([ResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ResourceClaimActionId, AuthorizationStrategyId
-FROM RelationshipsWithEdOrgsOnlyAuthorizationStrategies claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ResourceClaimActionAuthorizationStrategies] WHERE ResourceClaimActionId = claims.ResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* ==================================================================================================================================== */
-
-/* -------------------------------------------------------------- */
-/* ClaimSetResourceClaimActionAuthorizationStrategyOverrides */
-/* -------------------------------------------------------------- */
-
-/* Bootstrap Descriptors and EdOrgs Claims */
-
-SELECT @AuthorizationStrategyId = (SELECT AuthorizationStrategyId FROM [dbo].[AuthorizationStrategies]
- WHERE AuthorizationStrategyName = 'NoFurtherAuthorizationRequired');
-SELECT @ClaimSetId = (SELECT ClaimSetId FROM [dbo].[ClaimSets] WHERE [ClaimSetName] = 'Bootstrap Descriptors and EdOrgs');
-
-WITH ActionAuthorizationStrategyOverrides (ClaimSetResourceClaimActionId, AuthorizationStrategyId)
-AS
-(
- SELECT CSRCAA.ClaimSetResourceClaimActionId,@AuthorizationStrategyId FROM [dbo].[ClaimSetResourceClaimActions] CSRCAA
- INNER JOIN [dbo].[ResourceClaims] RC ON RC.ResourceClaimId =CSRCAA.ResourceClaimId
- INNER JOIN [dbo].[Actions] A on A.ActionId = CSRCAA.ActionId
- INNER JOIN [dbo].[ClaimSets] CS on CS.ClaimSetId = CSRCAA.ClaimSetId
- WHERE CS.ClaimSetId = @ClaimSetId
- AND A.ActionName IN ('Create')
- AND RC.ResourceName IN (
- 'systemDescriptors',
- 'managedDescriptors',
- 'educationOrganizations',
- -- from Interchange-Standards.xml
- 'learningObjective',
- 'learningStandard',
- 'learningStandardEquivalenceAssociation',
- -- from Interchange-EducationOrganization.xml
- 'accountabilityRating',
- 'classPeriod',
- 'communityOrganization',
- 'communityProvider',
- 'communityProviderLicense',
- 'course',
- 'educationOrganizationNetwork',
- 'educationOrganizationNetworkAssociation',
- 'educationOrganizationPeerAssociation',
- 'educationServiceCenter',
- 'feederSchoolAssociation',
- 'localEducationAgency',
- 'location',
- 'postSecondaryInstitution',
- 'program',
- 'school',
- 'stateEducationAgency')
-)
-INSERT INTO [dbo].[ClaimSetResourceClaimActionAuthorizationStrategyOverrides]
- ([ClaimSetResourceClaimActionId]
- ,[AuthorizationStrategyId])
-SELECT ClaimSetResourceClaimActionId, AuthorizationStrategyId
-FROM ActionAuthorizationStrategyOverrides claims
-WHERE NOT EXISTS (SELECT 1 FROM [dbo].[ClaimSetResourceClaimActionAuthorizationStrategyOverrides] WHERE ClaimSetResourceClaimActionId = claims.ClaimSetResourceClaimActionId
- AND AuthorizationStrategyId = claims.AuthorizationStrategyId);
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.pgsql.mustache b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.pgsql.mustache
deleted file mode 100644
index f25a19e5b1..0000000000
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Mustache/ResourceClaimMetadata.pgsql.mustache
+++ /dev/null
@@ -1,716 +0,0 @@
-begin transaction;
-
-/* --------------------------------- */
-/* Resource Claims */
-/* --------------------------------- */
-do $$
-
- declare typesResourceClaimId int;
- declare systemDescriptorsResourceClaimId int;
- declare managedDescriptorsResourceClaimId int;
- declare educationOrganizationsResourceClaimId int;
- declare peopleResourceClaimId int;
- declare relationshipBasedDataResourceClaimId int;
- declare assessmentMetadataResourceClaimId int;
- declare identityResourceClaimId int;
- declare educationStandardsResourceClaimId int;
- declare primaryRelationshipsResourceClaimId int;
- declare surveyDomainResourceClaimId int;
-begin
-
- select ResourceClaimId into typesResourceClaimId from dbo.ResourceClaims where ResourceName = 'types';
- select ResourceClaimId into systemDescriptorsResourceClaimId from dbo.ResourceClaims where ResourceName = 'systemDescriptors';
- select ResourceClaimId into managedDescriptorsResourceClaimId from dbo.ResourceClaims where ResourceName = 'managedDescriptors';
- select ResourceClaimId into educationOrganizationsResourceClaimId from dbo.ResourceClaims where ResourceName = 'educationOrganizations';
- select ResourceClaimId into peopleResourceClaimId from dbo.ResourceClaims where ResourceName = 'people';
- select ResourceClaimId into relationshipBasedDataResourceClaimId from dbo.ResourceClaims where ResourceName = 'relationshipBasedData';
- select ResourceClaimId into assessmentMetadataResourceClaimId from dbo.ResourceClaims where ResourceName = 'assessmentMetadata';
- select ResourceClaimId into identityResourceClaimId from dbo.ResourceClaims where ResourceName = 'identity';
- select ResourceClaimId into educationStandardsResourceClaimId from dbo.ResourceClaims where ResourceName = 'educationStandards';
- select ResourceClaimId into primaryRelationshipsResourceClaimId from dbo.ResourceClaims where ResourceName = 'primaryRelationships';
- select ResourceClaimId into surveyDomainResourceClaimId from dbo.ResourceClaims where ResourceName = 'surveyDomain';
-
-/* ------------------------------------------------- */
-/* Resource Claims */
-/* ------------------------------------------------ */
-
-{{#Aggregates}}
- IF NOT EXISTS(SELECT 1 FROM dbo.ResourceClaims WHERE ResourceName ='{{ResourceName}}') THEN
- insert into dbo.ResourceClaims (ResourceName, ClaimName, ParentResourceClaimId)
- values ('{{ResourceName}}', 'http://ed-fi.org/ods/identity/claims/{{ResourceName}}', {{#HasParent}}{{ParentResourceName}}ResourceClaimId{{/HasParent}}{{^HasParent}}null{{/HasParent}});
- END IF;
-
-{{/Aggregates}}
-end $$;
-
-/* ------------------------------------------------- */
-/* ClaimSetResourceClaimActions */
-/* ------------------------------------------------ */
-do $$
- declare claim_set_id int;
-begin
-
- /* SIS Vendors Claims */
-
- select ClaimSetId into claim_set_id from dbo.ClaimSets where ClaimSetName = 'SIS Vendor';
-
- WITH SisVendorClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read','Update','Delete')) as ac on true
- where ResourceName IN ('people'
- , 'relationshipBasedData'
- , 'assessmentMetadata'
- , 'managedDescriptors'
- , 'primaryRelationships'
- , 'educationStandards'
- , 'educationContent')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('people'
- , 'relationshipBasedData'
- , 'assessmentMetadata'
- , 'managedDescriptors'
- , 'primaryRelationships'
- , 'educationStandards'
- , 'educationContent')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from SisVendorClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* EdFi Sandbox Claims */
-
- select ClaimSetId INTO claim_set_id from dbo.ClaimSets where ClaimSetName = 'Ed-Fi Sandbox';
-
- WITH EdFiSandboxClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('types', 'identity')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create', 'Update')) as ac on true
- where ResourceName IN ('identity')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read','Update','Delete')) as ac on true
- where ResourceName IN ('systemDescriptors', 'educationOrganizations', 'people', 'relationshipBasedData',
- 'assessmentMetadata', 'managedDescriptors', 'primaryRelationships', 'educationStandards',
- 'educationContent', 'surveyDomain')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('systemDescriptors','educationOrganizations','people', 'relationshipBasedData',
- 'assessmentMetadata', 'managedDescriptors', 'primaryRelationships', 'educationStandards',
- 'educationContent', 'surveyDomain')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from EdFiSandboxClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* EdFi Sandbox Claims with Overrides */
-
- WITH EdFiSandboxClaimsWithOverrides AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast (null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create','Read','Update','Delete')) as ac on true
- where ResourceName IN ('communityProviderLicense')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from EdFiSandboxClaimsWithOverrides claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* Roster Vendor Claims */
-
- select ClaimSetId into claim_set_id from dbo.ClaimSets where ClaimSetName = 'Roster Vendor';
-
- WITH RosterVendorClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('educationOrganizations', 'section', 'student', 'staff', 'courseOffering',
- 'session', 'classPeriod', 'location', 'course', 'staffSectionAssociation',
- 'staffEducationOrganizationAssignmentAssociation', 'studentSectionAssociation', 'studentSchoolAssociation')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from RosterVendorClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* Assessment Vendor Claims */
-
- select ClaimSetId into claim_set_id from dbo.ClaimSets where ClaimSetName = 'Assessment Vendor';
-
- WITH AssessmentVendorClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create','Read','Update','Delete')) as ac on true
- where ResourceName IN ('academicSubjectDescriptor', 'assessmentMetadata', 'learningObjective', 'managedDescriptors', 'learningStandard')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('student', 'systemDescriptors', 'types')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from AssessmentVendorClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* Assessment Read Resource Claims */
-
- select ClaimSetId into claim_set_id from dbo.ClaimSets where ClaimSetName = 'Assessment Read';
-
- WITH AssessmentReadResourceClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('assessmentMetadata', 'learningObjective', 'learningStandard', 'student')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from AssessmentReadResourceClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* Bootstrap Descriptors and EdOrgs Claims */
-
- select ClaimSetId INTO claim_set_id from dbo.ClaimSets where ClaimSetName = 'Bootstrap Descriptors and EdOrgs';
-
- WITH BootstrapDescriptorsAndEdOrgsClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast (null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN (
- 'systemDescriptors',
- 'managedDescriptors',
- 'educationOrganizations',
- -- from Interchange-Standards.xml
- 'learningObjective',
- 'learningStandard',
- 'learningStandardEquivalenceAssociation',
- -- from Interchange-EducationOrganization.xml
- 'accountabilityRating',
- 'classPeriod',
- 'communityOrganization',
- 'communityProvider',
- 'communityProviderLicense',
- 'course',
- 'educationOrganizationNetwork',
- 'educationOrganizationNetworkAssociation',
- 'educationOrganizationPeerAssociation',
- 'educationServiceCenter',
- 'feederSchoolAssociation',
- 'localEducationAgency',
- 'location',
- 'postSecondaryInstitution',
- 'program',
- 'school',
- 'stateEducationAgency')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from BootstrapDescriptorsAndEdOrgsClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
- /* District Hosted SIS Vendor Claims */
-
- select ClaimSetId INTO claim_set_id from dbo.ClaimSets where ClaimSetName = 'District Hosted SIS Vendor';
-
- WITH DistrictHostedSisVendorClaims AS (
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'localEducationAgency')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Update')) as ac on true
- where ResourceName IN ('localEducationAgency')
- union
- select ac.ActionId, claim_set_id as ClaimSetId, ResourceClaimId, cast(null as int) as ValidationRuleSetNameOverride
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create','Read','Update','Delete')) as ac on true
- where ResourceName IN ('assessmentMetadata'
- , 'educationContent'
- , 'educationStandards'
- , 'managedDescriptors'
- , 'people'
- , 'primaryRelationships'
- , 'relationshipBasedData'
- , 'school'
- , 'organizationDepartment')
- )
- insert into dbo.ClaimSetResourceClaimActions
- (ActionId
- ,ClaimSetId
- ,ResourceClaimId
- ,ValidationRuleSetNameOverride)
- select ActionId, ClaimSetId, ResourceClaimId, ValidationRuleSetNameOverride
- from DistrictHostedSisVendorClaims claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActions where actionId = claims.actionId AND ClaimSetId = claims.ClaimSetId
- and ResourceClaimId = claims.ResourceClaimId);
-
-end $$;
-
-/* --------------------------------- */
-/* ResourceClaimActions */
-/* --------------------------------- */
-do $$
- declare authorization_strategy_id int;
-begin
-
- /* NoFurtherAuthorizationRequired */
-
- WITH NoFurtherAuthorizationRequiredResourceClaims AS (
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'course', 'managedDescriptors', 'identity', 'credential', 'person' )
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('educationOrganizations', 'credential', 'people', 'identity', 'person')
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Update')) as ac on true
- where ResourceName IN ('educationOrganizations', 'identity', 'credential', 'person' )
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Delete')) as ac on true
- where ResourceName IN ('educationOrganizations', 'people', 'credential', 'person')
- )
- insert into dbo.ResourceClaimActions
- (ActionId
- ,ResourceClaimId
- ,ValidationRuleSetName)
- select ActionId, ResourceClaimId, ValidationRuleSetName
- from NoFurtherAuthorizationRequiredResourceClaims claims
- where not exists (select 1 from dbo.ResourceClaimActions where actionId = claims.actionId AND ResourceClaimId = claims.ResourceClaimId);
-
- /* NamespaceBased */
-
- WITH NamespaceBasedResourceClaims AS (
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read')) as ac on true
- where ResourceName IN ('assessmentMetadata', 'educationStandards', 'educationContent', 'surveyDomain' )
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create', 'Update', 'Delete')) as ac on true
- where ResourceName IN ('systemDescriptors', 'managedDescriptors', 'assessmentMetadata', 'educationStandards', 'educationContent', 'surveyDomain')
- )
- insert into dbo.ResourceClaimActions
- (ActionId
- ,ResourceClaimId
- ,ValidationRuleSetName)
- select ActionId, ResourceClaimId, ValidationRuleSetName
- from NamespaceBasedResourceClaims claims
- where not exists (select 1 from dbo.ResourceClaimActions where actionId = claims.actionId AND ResourceClaimId = claims.ResourceClaimId);
-
- /* RelationshipsWithEdOrgsAndPeople */
-
- WITH RelationshipsWithEdOrgsAndPeopleResourceClaims AS (
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Read', 'Update')) as ac on true
- where ResourceName IN ('primaryRelationships', 'studentParentAssociation', 'people', 'relationshipBasedData', 'organizationDepartment')
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('relationshipBasedData', 'organizationDepartment')
- union
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Delete')) as ac on true
- where ResourceName IN ('relationshipBasedData', 'studentParentAssociation', 'primaryRelationships', 'organizationDepartment')
- )
- insert into dbo.ResourceClaimActions
- (ActionId
- ,ResourceClaimId
- ,ValidationRuleSetName)
- select ActionId, ResourceClaimId, ValidationRuleSetName
- from RelationshipsWithEdOrgsAndPeopleResourceClaims claims
- where not exists (select 1 from dbo.ResourceClaimActions where actionId = claims.actionId AND ResourceClaimId = claims.ResourceClaimId);
-
- /* RelationshipsWithStudentsOnly */
-
- WITH RelationshipsWithStudentsOnlyResourceClaims AS (
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('studentParentAssociation')
- )
- insert into dbo.ResourceClaimActions
- (ActionId
- ,ResourceClaimId
- ,ValidationRuleSetName)
- select ActionId, ResourceClaimId, ValidationRuleSetName
- from RelationshipsWithStudentsOnlyResourceClaims claims
- where not exists (select 1 from dbo.ResourceClaimActions where actionId = claims.actionId AND ResourceClaimId = claims.ResourceClaimId);
-
- /* RelationshipsWithEdOrgsOnly */
-
- WITH RelationshipsWithEdOrgsOnlyResourceClaims AS (
- select ac.ActionId, ResourceClaimId, cast(null as int) as ValidationRuleSetName
- from dbo.ResourceClaims
- inner join lateral
- (select ActionId
- from dbo.Actions
- where ActionName IN ('Create')) as ac on true
- where ResourceName IN ('primaryRelationships')
- )
- insert into dbo.ResourceClaimActions
- (ActionId
- ,ResourceClaimId
- ,ValidationRuleSetName)
- select ActionId, ResourceClaimId, ValidationRuleSetName
- from RelationshipsWithEdOrgsOnlyResourceClaims claims
- where not exists (select 1 from dbo.ResourceClaimActions where actionId = claims.actionId AND ResourceClaimId = claims.ResourceClaimId);
-
-end $$;
-
-/* ------------------------------------------ */
-/* ResourceClaimActionAuthorizationStrategies */
-/* ------------------------------------------ */
-
-do $$
- declare authorization_strategy_id int;
-begin
-
- /* NoFurtherAuthorizationRequired */
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
-
- WITH NoFurtherAuthorizationRequiredAuthorizationStrategies AS (
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName IN ('Read')
- and RC.ResourceName IN ('types', 'systemDescriptors', 'educationOrganizations', 'course', 'managedDescriptors', 'identity', 'credential', 'person')
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName IN ('Create')
- and RC.ResourceName IN ('educationOrganizations', 'credential', 'people', 'identity', 'person')
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName IN ('Update')
- and RC.ResourceName IN ('educationOrganizations', 'identity', 'credential', 'person' )
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC ON RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName IN ('Delete')
- and RC.ResourceName IN ('educationOrganizations', 'people', 'credential', 'person')
- )
- insert into dbo.ResourceClaimActionAuthorizationStrategies
- (ResourceClaimActionId
- ,AuthorizationStrategyId)
- select ResourceClaimActionId,AuthorizationStrategyId
- from NoFurtherAuthorizationRequiredAuthorizationStrategies claims
- where not exists (select 1 from dbo.ResourceClaimActionAuthorizationStrategies where ResourceClaimActionId = claims.ResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* NamespaceBased */
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'NamespaceBased';
-
- WITH NamespaceBasedAuthorizationStrategies AS (
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Read')
- and RC.ResourceName in ('assessmentMetadata', 'educationContent', 'surveyDomain' )
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Create', 'Update', 'Delete')
- and RC.ResourceName in ('systemDescriptors', 'managedDescriptors', 'assessmentMetadata', 'educationStandards', 'educationContent', 'surveyDomain')
- )
- insert into dbo.ResourceClaimActionAuthorizationStrategies
- (ResourceClaimActionId
- ,AuthorizationStrategyId)
- select ResourceClaimActionId,AuthorizationStrategyId
- from NamespaceBasedAuthorizationStrategies claims
- where not exists (select 1 from dbo.ResourceClaimActionAuthorizationStrategies where ResourceClaimActionId = claims.ResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithEdOrgsAndPeople */
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople';
-
- WITH RelationshipsWithEdOrgsAndPeopleAuthorizationStrategies AS (
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Read', 'Update')
- and RC.ResourceName in ('primaryRelationships', 'studentParentAssociation', 'people', 'relationshipBasedData', 'organizationDepartment')
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Create')
- and RC.ResourceName in ('relationshipBasedData', 'organizationDepartment')
- union
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Delete')
- and RC.ResourceName in ('relationshipBasedData', 'studentParentAssociation', 'primaryRelationships', 'organizationDepartment')
- )
- insert into dbo.ResourceClaimActionAuthorizationStrategies
- (ResourceClaimActionId
- ,AuthorizationStrategyId)
- select ResourceClaimActionId,AuthorizationStrategyId
- from RelationshipsWithEdOrgsAndPeopleAuthorizationStrategies claims
- where not exists (select 1 from dbo.ResourceClaimActionAuthorizationStrategies where ResourceClaimActionId = claims.ResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithStudentsOnly */
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'RelationshipsWithStudentsOnly';
-
- WITH RelationshipsWithStudentsOnlyAuthorizationStrategies AS (
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Create')
- and RC.ResourceName in ('studentParentAssociation')
- )
- insert into dbo.ResourceClaimActionAuthorizationStrategies
- (ResourceClaimActionId
- ,AuthorizationStrategyId)
- select ResourceClaimActionId,AuthorizationStrategyId
- from RelationshipsWithStudentsOnlyAuthorizationStrategies claims
- where not exists (select 1 from dbo.ResourceClaimActionAuthorizationStrategies where ResourceClaimActionId = claims.ResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-/* RelationshipsWithEdOrgsOnly */
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'RelationshipsWithEdOrgsOnly';
-
- WITH RelationshipsWithEdOrgsOnlyAuthorizationStrategies AS (
- select RCAA.ResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ResourceClaimActions RCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =RCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = RCAA.ActionId
- where A.ActionName in ('Create')
- and RC.ResourceName in ('primaryRelationships')
- )
- insert into dbo.ResourceClaimActionAuthorizationStrategies
- (ResourceClaimActionId
- ,AuthorizationStrategyId)
- select ResourceClaimActionId,AuthorizationStrategyId
- from RelationshipsWithEdOrgsOnlyAuthorizationStrategies claims
- where not exists (select 1 from dbo.ResourceClaimActionAuthorizationStrategies where ResourceClaimActionId = claims.ResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-end $$;
-
-/* --------------------------------------------------------------- */
-/* ClaimSetResourceClaimActionAuthorizationStrategyOverrides */
-/* --------------------------------------------------------------- */
-
-/* Bootstrap Descriptors and EdOrgs Claims */
-
-do $$
- declare claim_set_id int;
- declare authorization_strategy_id int;
-begin
-
- select AuthorizationStrategyId into authorization_strategy_id
- from dbo.AuthorizationStrategies
- where AuthorizationStrategyName = 'NoFurtherAuthorizationRequired';
-
- select ClaimSetId INTO claim_set_id from dbo.ClaimSets where ClaimSetName = 'Bootstrap Descriptors and EdOrgs';
-
- WITH ActionAuthorizationStrategyOverrides AS (
- select CSRCAA.ClaimSetResourceClaimActionId,authorization_strategy_id as AuthorizationStrategyId FROM dbo.ClaimSetResourceClaimActions CSRCAA
- inner join dbo.ResourceClaims RC on RC.ResourceClaimId =CSRCAA.ResourceClaimId
- inner join dbo.Actions A on A.ActionId = CSRCAA.ActionId
- inner join dbo.ClaimSets CS on CS.ClaimSetId = CSRCAA.ClaimSetId
- where CS.ClaimSetId = claim_set_id
- and A.ActionName in ('Create')
- and RC.ResourceName in (
- 'systemDescriptors',
- 'managedDescriptors',
- 'educationOrganizations',
- -- from Interchange-Standards.xml
- 'learningObjective',
- 'learningStandard',
- 'learningStandardEquivalenceAssociation',
- -- from Interchange-EducationOrganization.xml
- 'accountabilityRating',
- 'classPeriod',
- 'communityOrganization',
- 'communityProvider',
- 'communityProviderLicense',
- 'course',
- 'educationOrganizationNetwork',
- 'educationOrganizationNetworkAssociation',
- 'educationOrganizationPeerAssociation',
- 'educationServiceCenter',
- 'feederSchoolAssociation',
- 'localEducationAgency',
- 'location',
- 'postSecondaryInstitution',
- 'program',
- 'school',
- 'stateEducationAgency')
- )
- insert into dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides
- (ClaimSetResourceClaimActionId
- ,AuthorizationStrategyId)
- select ClaimSetResourceClaimActionId,AuthorizationStrategyId
- from ActionAuthorizationStrategyOverrides claims
- where not exists (select 1 from dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides where ClaimSetResourceClaimActionId = claims.ClaimSetResourceClaimActionId
- and AuthorizationStrategyId = claims.AuthorizationStrategyId);
-
-end $$;
-
-commit;
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Providers/Impl/LegacyDatabaseSpecificAssemblyDataProvider.cs b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Providers/Impl/LegacyDatabaseSpecificAssemblyDataProvider.cs
deleted file mode 100644
index 2a879fbb1e..0000000000
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/Providers/Impl/LegacyDatabaseSpecificAssemblyDataProvider.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-// 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.IO;
-using EdFi.Common;
-using EdFi.Ods.CodeGen.Conventions;
-using EdFi.Ods.CodeGen.Models;
-using EdFi.Ods.Common;
-using EdFi.Ods.Common.Conventions;
-using log4net;
-
-namespace EdFi.Ods.CodeGen.Providers.Impl
-{
- public class LegacyDatabaseSpecificAssemblyDataProvider : IAssemblyDataProvider
- {
- private static readonly ILog _logger = LogManager.GetLogger(typeof(AssembliesProvider));
-
- private readonly ICodeRepositoryProvider _codeRepositoryProvider;
- private readonly IStandardVersionPathProvider _standardVersionPathProvider;
-
- public LegacyDatabaseSpecificAssemblyDataProvider(ICodeRepositoryProvider codeRepositoryProvider,
- IStandardVersionPathProvider standardVersionPathProvider)
- {
- _codeRepositoryProvider = Preconditions.ThrowIfNull(codeRepositoryProvider, nameof(codeRepositoryProvider));
- _standardVersionPathProvider = standardVersionPathProvider;
- }
-
- public IEnumerable Get()
- {
- var assemblyData = new AssemblyData
- {
- AssemblyName = "ODS Database Specific",
- Path = GetPath(),
- TemplateSet = TemplateSetConventions.Database,
- IsExtension = false,
- SchemaName = EdFiConventions.ProperCaseName
- };
-
- _logger.Debug($"Created '{assemblyData.AssemblyName}' assembly data for '{assemblyData.Path}'");
-
- return new List { assemblyData };
-
- string GetPath()
- {
- var repositoryPath = _codeRepositoryProvider.GetCodeRepositoryByName(CodeRepositoryConventions.Ods);
- return Path.Combine(repositoryPath, CodeRepositoryConventions.Application, "EdFi.Ods.Standard",
- _standardVersionPathProvider.StandardVersionPath(), CodeRepositoryConventions.Database);
- }
- }
- }
-}
diff --git a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/TemplateSets.json b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/TemplateSets.json
index 20e4dd0c82..e02a1ee6f4 100644
--- a/Utilities/CodeGeneration/EdFi.Ods.CodeGen/TemplateSets.json
+++ b/Utilities/CodeGeneration/EdFi.Ods.CodeGen/TemplateSets.json
@@ -97,18 +97,6 @@
"OutputPath": "EntityOrmMappings/PgSql/EntityOrmMappingsForViews.generated.hbm.xml"
}
],
- "database": [
- {
- "Name": "ResourceClaimMetadata",
- "Driver": "ResourceClaimMetadata",
- "OutputPath": "MsSql/Data/Security/0002-ResourceClaimMetadata_generated.sql"
- },
- {
- "Name": "ResourceClaimMetadata.pgsql",
- "Driver": "ResourceClaimMetadata",
- "OutputPath": "PgSql/Data/Security/0002-ResourceClaimMetadata_generated.sql"
- }
- ],
"extension": [
{
"Name": "EntityAuthorizationContextProviders",
diff --git a/Utilities/Directory.Build.props b/Utilities/Directory.Build.props
index 7ab7d9421b..a56a34426a 100644
--- a/Utilities/Directory.Build.props
+++ b/Utilities/Directory.Build.props
@@ -1,5 +1,8 @@
+ true
+ high
+ direct
Copyright © $([System.DateTime]::Now.ToString(`yyyy`)) Ed-Fi Alliance, LLC and Contributors