Skip to content

Commit

Permalink
[BIA-864] Adjusts SessionKey on AcademicTimePeriodDim to meet DS3 def…
Browse files Browse the repository at this point in the history
…inition
  • Loading branch information
nsd-daniel authored Oct 18, 2021
1 parent d2bd545 commit ac58904
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- 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.

IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'analytics' AND TABLE_NAME = 'AcademicTimePeriodDim')
BEGIN
DROP VIEW analytics.AcademicTimePeriodDim
END
GO

CREATE VIEW analytics.AcademicTimePeriodDim
AS
SELECT
FORMATMESSAGE(
'%s-%s-%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.TermDescriptorId as VARCHAR),
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
CONVERT(VARCHAR, GradingPeriod.BeginDate, 112)
) as AcademicTimePeriodKey,
CAST(SchoolYearType.SchoolYear as VARCHAR) as SchoolYear,
SchoolYearType.SchoolYearDescription as SchoolYearName,
SchoolYearType.CurrentSchoolYear as IsCurrentSchoolYear,
CAST(Session.SchoolId as VARCHAR) as SchoolKey,
FORMATMESSAGE(
'%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.SessionName as VARCHAR)
) as SessionKey,
Session.SessionName,
Descriptor.Description as TermName,
FORMATMESSAGE(
'%s-%s-%s',
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
CAST(GradingPeriod.SchoolId as VARCHAR),
CONVERT(VARCHAR, GradingPeriod.BeginDate, 112)
) as GradingPeriodKey,
gpDescriptor.Description as GradingPeriodName,
(
SELECT MAX(MaxLastModifiedDate)
FROM (
VALUES
(SchoolYearType.LastModifiedDate),
(Session.LastModifiedDate),
(GradingPeriod.LastModifiedDate)
) as VALUE(MaxLastModifiedDate)
) as LastModifiedDate
FROM
edfi.SchoolYearType
INNER JOIN
edfi.Session
ON
SchoolYearType.SchoolYear = Session.SchoolYear
INNER JOIN
edfi.Descriptor
ON
Session.TermDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.SessionGradingPeriod
ON
Session.SchoolYear = SessionGradingPeriod.SchoolYear
AND
Session.SessionName = SessionGradingPeriod.SessionName
AND
Session.SchoolId = SessionGradingPeriod.SchoolId
INNER JOIN
edfi.GradingPeriod
ON
SessionGradingPeriod.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId
AND
SessionGradingPeriod.PeriodSequence = GradingPeriod.PeriodSequence
AND
SessionGradingPeriod.SchoolId = GradingPeriod.SchoolId
AND
Session.SchoolYear = GradingPeriod.SchoolYear
INNER JOIN
edfi.Descriptor as gpDescriptor
ON
GradingPeriod.GradingPeriodDescriptorId = gpDescriptor.DescriptorId

GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- 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.

IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'analytics' AND TABLE_NAME = 'AcademicTimePeriodDim')
BEGIN
DROP VIEW analytics.AcademicTimePeriodDim
END
GO

CREATE VIEW analytics.AcademicTimePeriodDim
AS
SELECT
FORMATMESSAGE(
'%s-%s-%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.TermDescriptorId as VARCHAR),
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
CONVERT(VARCHAR, GradingPeriod.BeginDate, 112)
) as AcademicTimePeriodKey,
CAST(SchoolYearType.SchoolYear as VARCHAR) as SchoolYear,
SchoolYearType.SchoolYearDescription as SchoolYearName,
SchoolYearType.CurrentSchoolYear as IsCurrentSchoolYear,
CAST(Session.SchoolId as VARCHAR) as SchoolKey,
FORMATMESSAGE(
'%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.SessionName as VARCHAR)
) as SessionKey,
Session.SessionName,
Descriptor.Description as TermName,
FORMATMESSAGE(
'%s-%s-%s',
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
CAST(GradingPeriod.SchoolId as VARCHAR),
CONVERT(VARCHAR, GradingPeriod.BeginDate, 112)
) as GradingPeriodKey,
gpDescriptor.Description as GradingPeriodName,
(
SELECT MAX(MaxLastModifiedDate)
FROM (
VALUES
(SchoolYearType.LastModifiedDate),
(Session.LastModifiedDate),
(GradingPeriod.LastModifiedDate)
) as VALUE(MaxLastModifiedDate)
) as LastModifiedDate
FROM
edfi.SchoolYearType
INNER JOIN
edfi.Session
ON
SchoolYearType.SchoolYear = Session.SchoolYear
INNER JOIN
edfi.Descriptor
ON
Session.TermDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.SessionGradingPeriod
ON
Session.SchoolYear = SessionGradingPeriod.SchoolYear
AND
Session.SessionName = SessionGradingPeriod.SessionName
AND
Session.SchoolId = SessionGradingPeriod.SchoolId
INNER JOIN
edfi.GradingPeriod
ON
SessionGradingPeriod.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId
AND
SessionGradingPeriod.PeriodSequence = GradingPeriod.PeriodSequence
AND
SessionGradingPeriod.SchoolId = GradingPeriod.SchoolId
AND
Session.SchoolYear = GradingPeriod.SchoolYear
INNER JOIN
edfi.Descriptor as gpDescriptor
ON
GradingPeriod.GradingPeriodDescriptorId = gpDescriptor.DescriptorId

GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- 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.

DROP VIEW IF EXISTS analytics.AcademicTimePeriodDim;

CREATE VIEW analytics.AcademicTimePeriodDim
AS
SELECT
FORMAT(
'%s-%s-%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.TermDescriptorId as VARCHAR),
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
to_char(GradingPeriod.BeginDate, 'yyyymmdd')
) as AcademicTimePeriodKey,
CAST(SchoolYearType.SchoolYear as VARCHAR) as SchoolYear,
SchoolYearType.SchoolYearDescription as SchoolYearName,
SchoolYearType.CurrentSchoolYear as IsCurrentSchoolYear,
CAST(Session.SchoolId as VARCHAR) as SchoolKey,
FORMAT(
'%s-%s-%s',
CAST(Session.SchoolId as VARCHAR),
CAST(Session.SchoolYear as VARCHAR),
CAST(Session.SessionName as VARCHAR)
) as SessionKey,
Session.SessionName,
Descriptor.Description as TermName,
FORMAT(
'%s-%s-%s',
CAST(GradingPeriod.GradingPeriodDescriptorId as VARCHAR),
CAST(GradingPeriod.SchoolId as VARCHAR),
to_char(GradingPeriod.BeginDate, 'yyyymmdd')
) as GradingPeriodKey,
gpDescriptor.Description as GradingPeriodName,
(
SELECT MAX(MaxLastModifiedDate)
FROM (
VALUES
(SchoolYearType.LastModifiedDate),
(Session.LastModifiedDate),
(GradingPeriod.LastModifiedDate)
) as VALUE(MaxLastModifiedDate)
) as LastModifiedDate
FROM
edfi.SchoolYearType
INNER JOIN
edfi.Session
ON
SchoolYearType.SchoolYear = Session.SchoolYear
INNER JOIN
edfi.Descriptor
ON
Session.TermDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.SessionGradingPeriod
ON
Session.SchoolYear = SessionGradingPeriod.SchoolYear
AND
Session.SessionName = SessionGradingPeriod.SessionName
AND
Session.SchoolId = SessionGradingPeriod.SchoolId
INNER JOIN
edfi.GradingPeriod
ON
SessionGradingPeriod.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId
AND
SessionGradingPeriod.PeriodSequence = GradingPeriod.PeriodSequence
AND
SessionGradingPeriod.SchoolId = GradingPeriod.SchoolId
AND
Session.SchoolYear = GradingPeriod.SchoolYear
INNER JOIN
edfi.Descriptor as gpDescriptor
ON
GradingPeriod.GradingPeriodDescriptorId = gpDescriptor.DescriptorId;
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Then_should_have_SessionKey()
{
(bool success, string errorMessage) testResult = DataStandard
.RunTestCase<AcademicTimePeriodDim>(
$"{TestCasesFolder}.{DataStandard.DataStandardBaseVersion}.should_have_SessionKey.xml");
$"{TestCasesFolder}.{DataStandard.DataStandardFolderName}.should_have_SessionKey.xml");
testResult.success.ShouldBe(true, testResult.errorMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="TestCases\AcademicTimePeriodDim\MSSQL\" />
<Folder Include="TestCases\ContactPersonDim\MSSQL\" />
<Folder Include="TestCases\DateDim\MSSQL\" />
<Folder Include="TestCases\DateDim\PostgreSQL\" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</Query>
<Result>
<SessionKey>
867530010-2012-1
867530010-2012-1
</SessionKey>
</Result>
</TestCase>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</Query>
<Result>
<SessionKey>
867530010-2012-1
867530010-2012-Grading period is the last mod
</SessionKey>
</Result>
</TestCase>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<TestCase>
<DBMS>Any</DBMS>
<ControlDataInsertion>
</ControlDataInsertion>
<Query>
SELECT SessionKey
FROM analytics.AcademicTimePeriodDim
WHERE SessionName = 'Grading period is the last modified';
</Query>
<Result>
<SessionKey>
867530010-2012-Grading period is the last modified
</SessionKey>
</Result>
</TestCase>

0 comments on commit ac58904

Please sign in to comment.