public void When_getting_all_descriptor_lookups_should_return_all_entries() { var descriptorsLookup = DescriptorLookupProvider.GetAllDescriptorLookups(); var testLookup1 = descriptorsLookup.Values.SelectMany(tlv => tlv) .SingleOrDefault( dl => dl.DescriptorName == CountryDescriptorName && dl.Id == CountryTestDescriptor1.CountryDescriptorId); testLookup1.ShouldNotBeNull(); testLookup1.Id.ShouldBe(CountryTestDescriptor1.CountryDescriptorId); testLookup1.DescriptorValue.ShouldBe( EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( CountryTestDescriptor1.Namespace, CountryTestDescriptor1.CodeValue)); var testLookup2 = descriptorsLookup.Values.SelectMany(tlv => tlv) .SingleOrDefault( dl => dl.DescriptorName == CountryDescriptorName && dl.Id == CountryTestDescriptor2.CountryDescriptorId); testLookup2.ShouldNotBeNull(); testLookup2.Id.ShouldBe(CountryTestDescriptor2.CountryDescriptorId); testLookup2.DescriptorValue.ShouldBe( EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( CountryTestDescriptor2.Namespace, CountryTestDescriptor2.CodeValue)); var testLookup3 = descriptorsLookup.Values.SelectMany(tlv => tlv) .SingleOrDefault( dl => dl.DescriptorName == CountryDescriptorName && dl.Id == CountryTestDescriptor3.CountryDescriptorId); testLookup3.ShouldNotBeNull(); testLookup3.Id.ShouldBe(CountryTestDescriptor3.CountryDescriptorId); testLookup3.DescriptorValue.ShouldBe( EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( CountryTestDescriptor3.Namespace, CountryTestDescriptor3.CodeValue)); var testLookup4 = descriptorsLookup.Values.SelectMany(tlv => tlv) .SingleOrDefault( dl => dl.DescriptorName == AssessmentPeriodDescriptorName && dl.Id == AssessmentPeriodTestDescriptor1.AssessmentPeriodDescriptorId); testLookup4.ShouldNotBeNull(); testLookup4.Id.ShouldBe(AssessmentPeriodTestDescriptor1.AssessmentPeriodDescriptorId); testLookup4.DescriptorValue.ShouldBe( EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( AssessmentPeriodTestDescriptor1.Namespace, AssessmentPeriodTestDescriptor1.CodeValue)); }
private IEnumerable <KeyValuePair <string, object> > EnumerateKeyValuePairs( Hashtable sourceRow, NullValueHandling nullValueHandling, IEnumerable <string> keysToProcess, Dictionary <string, object> descriptorNamespaceByKey, HashSet <string> selectedKeys) { foreach (string key in keysToProcess) { string renamedKey = null; // Handle Pass through values if (key.EndsWith(CompositeDefinitionHelper.PassThroughMarker)) { renamedKey = key.TrimSuffix(CompositeDefinitionHelper.PassThroughMarker); yield return(new KeyValuePair <string, object>(renamedKey ?? key, sourceRow[key])); } else { // Remove null values, if appropriate object value; if (sourceRow[key] == null) { if (nullValueHandling == NullValueHandling.Include) { value = sourceRow[key]; } else { continue; } } else { if (descriptorNamespaceByKey.TryGetValue(key, out object namespaceForDescriptor)) { value = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( namespaceForDescriptor.ToString(), sourceRow[key] .ToString()); } else { // See if we need to convert an USI to a UniqueId if (UniqueIdSpecification.IsUSI(key) && UniqueIdSpecification.TryGetUSIPersonTypeAndRoleName(key, out string personType, out string roleName)) { // Translate to UniqueId string uniqueId = _personUniqueIdToUsiCache.GetUniqueId(personType, (int)sourceRow[key]); string uniqueIdKey = (roleName + personType + CompositeDefinitionHelper.UniqueId).ToCamelCase(); renamedKey = uniqueIdKey; value = uniqueId; }
public string GetValue(string descriptorName, int id) { if (id == 0) { return(null); } return(EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( $"uri://ed-fi.org/{descriptorName}", descriptorName.Substring(0, 1) + id)); }
public ValueBuildResult TryBuild(BuildContext buildContext) { string propertyName = buildContext.GetPropertyName(); string logicalPath = buildContext.LogicalPropertyPath; var containingInstance = buildContext.GetContainingInstance(); if (propertyName.EndsWith(_propertySuffix)) { var descriptorValue = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( $"uri://ed-fi.org/{propertyName}", propertyName.Substring(0, 1)); var alreadyAssignedId = GetPropertyValue <int>(containingInstance, propertyName + "Id"); // If already assigned, build new value based on existing Id if (alreadyAssignedId != 0) { return(ValueBuildResult.WithValue(descriptorValue + alreadyAssignedId, logicalPath)); } string key = ProcessPathForLeafCollectionCounterResetBehavior(logicalPath); int number = _numberByTypeName.GetOrAdd(logicalPath, x => 1); var result = ValueBuildResult.WithValue(descriptorValue + number++, logicalPath); _numberByTypeName[key] = number; return(result); } if (propertyName.EndsWith(_propertySuffix + "Id")) { string valuePropertyName = propertyName.TrimSuffix("Id"); string valueLogicalPath = logicalPath.TrimSuffix("Id"); string alreadyAssignedValue = GetPropertyValue <string>(containingInstance, valuePropertyName); // If already assigned, extract Id from the value if (alreadyAssignedValue != null) { return(ValueBuildResult.WithValue(Convert.ToInt32(alreadyAssignedValue.Last()), logicalPath)); } string key = ProcessPathForLeafCollectionCounterResetBehavior(valueLogicalPath); int number = _numberByTypeName.GetOrAdd(key, x => 1); var result = ValueBuildResult.WithValue(number++, logicalPath); _numberByTypeName[key] = number; return(result); } return(ValueBuildResult.NotHandled); }
private static IEnumerable <DescriptorLookup> TransformToDescriptorLookups( string descriptorName, IEnumerable <DescriptorEntry> descriptorEntries) { return(descriptorEntries.Select( d => new DescriptorLookup { DescriptorName = descriptorName, DescriptorValue = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( d.Namespace, d.CodeValue), Id = d.Id })); }
public void When_getting_valid_descriptor_by_id_should_return_lookup_data() { var testLookup = DescriptorLookupProvider.GetSingleDescriptorLookupById( CountryDescriptorName, CountryTestDescriptor1.CountryDescriptorId); testLookup.ShouldNotBeNull(); testLookup.Id.ShouldBe(CountryTestDescriptor1.CountryDescriptorId); testLookup.DescriptorValue.ShouldBe( EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( CountryTestDescriptor1.Namespace, CountryTestDescriptor1.CodeValue)); }
protected override void Act() { // ---------------------------------------------------------------------- // Create a new StudentProgramAssociation with a service // ---------------------------------------------------------------------- var studentProgramAssociation = new StudentProgramAssociation { StudentUniqueId = _student.StudentUniqueId, ProgramTypeDescriptor = _program1.ProgramTypeDescriptor, ProgramName = _program1.ProgramName, ProgramEducationOrganizationId = _educationOrganization1, BeginDate = DateTime.Today.AddDays(-60), EducationOrganizationId = _educationOrganization1 }; var service = new StudentProgramAssociationService { ServiceDescriptor = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( _serviceDescriptor.Namespace, _serviceDescriptor.CodeValue), PrimaryIndicator = true, StudentProgramAssociation = studentProgramAssociation }; studentProgramAssociation.StudentProgramAssociationServices.Add(service); var studentProgramAssociationUpsertResult = _studentProgramAssociationRepo.UpsertAsync( studentProgramAssociation, false, CancellationToken.None) .GetResultSafely(); _actualStudentProgramAssociationUpsert1Results = new UpsertResults { IsCreated = studentProgramAssociationUpsertResult.IsCreated, IsModified = studentProgramAssociationUpsertResult.IsModified }; // ---------------------------------------------------------------------- // Update the StudentProgramAssociation, removing the service // ---------------------------------------------------------------------- var studentProgramAssociation2 = new StudentProgramAssociation { StudentUniqueId = _student.StudentUniqueId, ProgramTypeDescriptor = _program1.ProgramTypeDescriptor, ProgramName = _program1.ProgramName, ProgramEducationOrganizationId = _educationOrganization1, BeginDate = DateTime.Today.AddDays(-60), ReasonExitedDescriptor = KnownDescriptors.ReasonExited.MovedOutOfState, EducationOrganizationId = _educationOrganization1 }; studentProgramAssociationUpsertResult = _studentProgramAssociationRepo.UpsertAsync( studentProgramAssociation2, false, CancellationToken.None) .GetResultSafely(); _actualStudentProgramAssociationUpsert2Results = new UpsertResults { IsCreated = studentProgramAssociationUpsertResult.IsCreated, IsModified = studentProgramAssociationUpsertResult.IsModified }; // Verify the service got removed using (var conn = GetSqlConnectionForOds()) { conn.Open(); var cmd = new SqlCommand( $"SELECT COUNT(*) FROM edfi.StudentProgramAssociationService WHERE ProgramName = '{_program1.ProgramName}'", conn); _actualServiceDeletedWithSecondUpsert = 0 == Convert.ToInt32(cmd.ExecuteScalar()); } // ------------------------------------------------------------------------------------------------------------- // Create a new (derived class) StudentTitleIPartAProgramAssociation with a service hanging off the base class // ------------------------------------------------------------------------------------------------------------- var studentTitleIPartA = new StudentTitleIPartAProgramAssociation { // PK StudentUniqueId = _student.StudentUniqueId, ProgramTypeDescriptor = _program2.ProgramTypeDescriptor, ProgramName = _program2.ProgramName, ProgramEducationOrganizationId = _educationOrganization1, BeginDate = DateTime.Today.AddDays(-60), EducationOrganizationId = _educationOrganization2, // Base class property ReasonExitedDescriptor = KnownDescriptors.ReasonExited.MovedOutOfState, // Derived class property TitleIPartAParticipantDescriptor = KnownDescriptors.TitleIPartAParticipant.LocalNeglectedProgram }; // Add a service to the base class var titleIService = new StudentTitleIPartAProgramAssociationService { ServiceDescriptor = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( _serviceDescriptor.Namespace, _serviceDescriptor.CodeValue), PrimaryIndicator = true, StudentTitleIPartAProgramAssociation = studentTitleIPartA }; studentTitleIPartA.StudentTitleIPartAProgramAssociationServices.Add(titleIService); var studentTitleIPartAProgramAssociationUpsertResult = _studentTitleIPartAProgramAssociationRepo.UpsertAsync( studentTitleIPartA, false, CancellationToken.None) .GetResultSafely(); _actualStudentTitleIPartAUpsert1Results = new UpsertResults { IsCreated = studentTitleIPartAProgramAssociationUpsertResult.IsCreated, IsModified = studentTitleIPartAProgramAssociationUpsertResult.IsModified }; // ------------------------------------------------------------------------------------------------------------- // Create a new (derived class) StudentTitleIPartAProgramAssociation with a service hanging off the base class // ------------------------------------------------------------------------------------------------------------- var studentTitleIPartA2 = new StudentTitleIPartAProgramAssociation { // PK StudentUniqueId = _student.StudentUniqueId, ProgramTypeDescriptor = _program2.ProgramTypeDescriptor, ProgramName = _program2.ProgramName, ProgramEducationOrganizationId = _educationOrganization1, BeginDate = DateTime.Today.AddDays(-60), EducationOrganizationId = _educationOrganization2, // Base class property ReasonExitedDescriptor = KnownDescriptors.ReasonExited.GraduatedWithAHighSchoolDiploma, // Derived class property TitleIPartAParticipantDescriptor = KnownDescriptors.TitleIPartAParticipant.PublicSchoolwideProgram }; // Updating derived record, removing the service studentTitleIPartAProgramAssociationUpsertResult = _studentTitleIPartAProgramAssociationRepo.UpsertAsync( studentTitleIPartA2, false, CancellationToken.None) .GetResultSafely(); _actualStudentTitleIPartAUpsert2Results = new UpsertResults { IsCreated = studentTitleIPartAProgramAssociationUpsertResult.IsCreated, IsModified = studentTitleIPartAProgramAssociationUpsertResult.IsModified }; // Verify the service got removed using (var conn = GetSqlConnectionForOds()) { conn.Open(); var cmd = new SqlCommand( $"SELECT COUNT(*) FROM edfi.StudentProgramAssociationService WHERE ProgramName = '{_program2.ProgramName}'", conn); _actualServiceDeletedWithSecondDerivedClassUpsert = 0 == Convert.ToInt32(cmd.ExecuteScalar()); } // Clean up the data now // Delete the concrete base class (StudentProgramAssociation) try { var deleteStudentProgramAssociationByKey = _container.Resolve <IDeleteEntityByKey <StudentProgramAssociation> >(); deleteStudentProgramAssociationByKey.DeleteByKeyAsync(studentProgramAssociation, null, CancellationToken.None) .WaitSafely(); } catch (Exception ex) { _actualDeleteStudentProgramAssociationException = ex; } // Verify the program association got removed using (var conn = GetSqlConnectionForOds()) { conn.Open(); var cmd = new SqlCommand( $"SELECT COUNT(*) FROM edfi.StudentProgramAssociationService WHERE ProgramName = '{_program1.ProgramName}'", conn); _actualProgramAssociationDeleted = 0 == Convert.ToInt32(cmd.ExecuteScalar()); } // Delete the derived class (StudentProgramAssociation) try { var deletestudentTitleIPartAAssociationById = _container.Resolve <IDeleteEntityById <StudentTitleIPartAProgramAssociation> >(); deletestudentTitleIPartAAssociationById.DeleteByIdAsync( studentTitleIPartA.Id, null, CancellationToken.None) .WaitSafely(); } catch (Exception ex) { _actualDeleteStudentTitleIPartAAssociationException = ex; } // Verify the TitleI program association got removed using (var conn = GetSqlConnectionForOds()) { conn.Open(); var cmd = new SqlCommand( $"SELECT COUNT(*) FROM edfi.StudentProgramAssociationService WHERE ProgramName = '{_program2.ProgramName}'", conn); _actualTitleIProgramAssociationDeleted = 0 == Convert.ToInt32(cmd.ExecuteScalar()); } }
protected string GetRef(string codeValue) { return(EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( DescriptorNamespacePrefix, codeValue)); }