예제 #1
0
        /// <summary>
        /// Get the Layout information for a supplied Template and Metadata.
        /// The Metadata is used to lookup identifier information.
        /// </summary>
        private TemplateLayout GetTemplateLayout(Template template, DataEntryContract dataEntryContract, string implementation)
        {
            // Create the Template Layout
            // This information can be used to create a new Template in a Different System that structurally matches the original.
            var templateLayout =
                new TemplateLayout()
            {
                ApiVersion        = template.ApiVersion,
                Description       = template.Description,
                Implementation    = implementation,
                IsSupplement      = template.IsSupplement,
                ModuleType        = template.ModuleType,
                Name              = template.Name,
                Sections          = new List <SectionLayout>(),
                ValidationEnabled = template.ValidationEnabled,
                IsDefault         = false // This Value is not part of the actual Layout. This is a placeholder for data that is managed elsewhere.
            };

            // Create Scaffolding for Each Section
            foreach (var section in template.Sections)
            {
                // Get the Section Metadata
                var dataEntrySection = dataEntryContract.GetSection(section.DataEntrySectionId);
                templateLayout.Sections.Add(GetSectionLayout(section, dataEntrySection));
            }

            return(templateLayout);
        }
예제 #2
0
        /// <summary>
        /// Load the Layout Information to an Existing Template Instance.
        /// </summary>
        /// <param name="layout">The Layout Information to apply.</param>
        /// <param name="template">The Template Instance to apply the layout to.</param>
        /// <param name="dataEntryContract">Local Metadata for the Template.</param>
        private void LoadLayout(TemplateLayout layout, Template template, DataEntryContract dataEntryContract)
        {
            // Load the Template Information
            template.Description       = layout.Description;
            template.IsSupplement      = layout.IsSupplement;
            template.ValidationEnabled = layout.ValidationEnabled;

            // Apply the Section Layouts
            foreach (var sectionLayout in layout.Sections)
            {
                // Lookup the Section Information
                var sectionMetadata = dataEntryContract.GetSection(sectionLayout.DataEntrySectionName);
                var section         = template.GetSection(sectionMetadata.Id);

                // If the Section does not exist in the Template, create a new section
                // using the layout information and add it to the Template.
                if (section == null)
                {
                    // Create a new section using the layout
                    section = template.CreateSection(sectionMetadata.Id, sectionLayout.Label);
                    template.Sections.Add(section);
                }

                // Apply the Layout to the Section
                ApplySectionLayout(sectionLayout, section, sectionMetadata);
            }
        }
예제 #3
0
        public static Template Create(Agency agency, DataEntryContract contract)
        {
            var template = agency.CreateTemplate(contract.ModuleType, contract.Name);

            template.Description = contract.Description;
            BuildSections(template, contract);
            return(template);
        }
예제 #4
0
 /// <summary>
 /// Loads the information in a DataEntryContract into a Template.
 /// This assumes the template does not already contain information for the contract.
 /// Remember to Reset the Template Layout First!
 /// </summary>
 public void LoadFromMeta(Template template, DataEntryContract dataEntryContract)
 {
     foreach (var dataEntrySection in dataEntryContract.Sections.OrderBy(x => x.OrderBy))
     {
         var section = template.CreateSection(dataEntrySection.Id, dataEntrySection.Label);
         LoadFromMeta(section, dataEntrySection);
     }
 }
예제 #5
0
        private DataEntryContract CreateDataEntryContract(ModuleType moduleType)
        {
            var dataEntryContract = new DataEntryContract {
                ModuleType = moduleType
            };

            return(dataEntryContract);
        }
예제 #6
0
 private static void BuildSections(Template template, DataEntryContract contract)
 {
     foreach (var dataEntrySection in contract.Sections.OrderBy(x => x.OrderBy))
     {
         var section = template.CreateSection(dataEntrySection.Name, dataEntrySection.SectionType);
         section.OrderBy     = dataEntrySection.OrderBy;
         section.Description = dataEntrySection.Description;
         BuildFields(section, dataEntrySection);
     }
 }
        public void MetadataQueryService_GetDataEntryContractForCitation()
        {
            var metadataQueryService = GetDependency <IDataEntryMetadataQueryService>();

            Assert.IsInstanceOfType(metadataQueryService, typeof(IDataEntryMetadataQueryService));
            DataEntryContract dataEntryContract = metadataQueryService.GetDataEntryContract(ModuleType.Citation);

            Assert.IsNotNull(dataEntryContract);
            Assert.AreEqual(ModuleType.Citation, dataEntryContract.ModuleType);
            Assert.IsInstanceOfType(dataEntryContract, typeof(DataEntryContract));
        }
예제 #8
0
        public void GetMetaData_PasswordController_MoqTest()
        {
            mockIDataEntryMetadataQueryService.Setup(x => x.GetDataEntryContract(It.IsAny <ModuleType>()))
            .Returns(dataEntryContract);

            var controller = new TemplateMetaController(mockIDataEntryMetadataQueryService.Object, mockIDataEntryMetadataCommandService.Object);
            DataEntryContract actionResult = controller.GetMetaData(It.IsAny <ModuleType>());

            Assert.AreEqual(dataEntryContract.Id, actionResult.Id);
            Assert.AreEqual(dataEntryContract.ModuleType, actionResult.ModuleType);
            Assert.AreEqual(dataEntryContract.TypeName, actionResult.TypeName);
            Assert.IsNull(actionResult.Sections);
        }
예제 #9
0
        public void CreateCustomField()
        {
            var dataEntryContractList    = new List <DataEntryContract>();
            var dataEntryContractDetails = new DataEntryContract();

            dataEntryContractDetails.ModuleType = ModuleType.Arrest;
            dataEntryContractList.Add(dataEntryContractDetails);
            _metadataUnitOfWork.Setup(mock => mock.GetEntityQuery <DataEntryContract>(TrackingMode.Automatic)).Returns(dataEntryContractList.AsQueryable());
            var dataEntryContract = _dataEntryMetadataQueryService.GetDataEntryContract(ModuleType.Arrest);

            dataEntryContract.Should().NotBeNull();
            dataEntryContract.Should().BeOfType(typeof(DTO.DataEntryContract));
            dataEntryContract.ModuleType.Should().Be(dataEntryContractDetails.ModuleType);
            _metadataUnitOfWork.VerifyAll();
        }
예제 #10
0
        private static void ProcessDataContractSections(DataEntryContract contract, Type type, string implementation)
        {
            foreach (var property in type.GetProperties())
            {
                // Get the type of the Section
                var sectionType = PropertyTypeIsCollectionOfSections(property) ? GenericParameterType(property.PropertyType) : property.PropertyType;

                // Get the Section Attribute from the Property Type
                var sectionAttribute = GetSectionAttribute(sectionType);

                // Only Process Section Types
                if (sectionAttribute == null)
                {
                    continue;
                }

                // Get the Section Attribute
                var sectionAttr = GetSectionAttribute(sectionType);
                // If the property is not a section continue
                if (sectionAttr == null)
                {
                    continue;
                }

                // Create a DataEntrySection
                var dataEntrySection = new DataEntrySection()
                {
                    OrderBy      = contract.Sections.Count,
                    Name         = property.Name,
                    Path         = property.Name.ToPascalCase(),
                    Label        = GetLabel(property) ?? property.Name.ToEnglish(),
                    Description  = GetDescription(sectionType),
                    IsCollection = IsCollection(property.PropertyType),
                    PropertyName = property.Name,
                    SectionType  = sectionAttr.SectionType,
                    TypeName     = sectionType.FullName
                };

                // Add the section to the contract
                contract.Sections.Add(dataEntrySection);

                // Process the properties on the Section's Type.
                ProcessSectionProperties(dataEntrySection, sectionType, null, null, implementation);
            }
        }
예제 #11
0
        private static void ProcessSectionProperty(DataEntryContract contract, PropertyInfo property, Type sectionType, SectionAttribute sectionAttribute)
        {
            // Create the Section Metadata
            var sectionContract = new DataEntrySection()
            {
                OrderBy       = contract.Sections.Count,
                Name          = property.Name,
                Path          = property.Name.ToPascalCase(),
                Label         = GetLabel(property) ?? MakeEnglish(property.Name),
                Description   = GetDescription(sectionType),
                AllowMultiple = IsCollection(property.PropertyType),
                PropertyName  = property.Name,
                SectionType   = sectionAttribute.SectionType,
                TypeName      = sectionType.FullName
            };

            // Process the Field Metadata
            ProcessSectionFields(sectionContract, sectionAttribute, sectionType);
            contract.Sections.Add(sectionContract);
        }
예제 #12
0
        private static void ProcessContractSections(DataEntryContract contract, Type contractType)
        {
            foreach (var property in contractType.GetProperties())
            {
                // Get the type of the Section
                var sectionType = PropertyTypeIsCollectionOfSections(property) ? GenericParameterType(property.PropertyType) : property.PropertyType;

                // Get the Section Attribute from the Property Type
                var sectionAttribute = GetSectionAttribute(sectionType);

                // Only Process Section Types
                if (sectionAttribute == null)
                {
                    continue;
                }

                // Process the Section
                ProcessSectionProperty(contract, property, sectionType, sectionAttribute);
            }
        }
예제 #13
0
        public static DataEntryContract GetContractInfo(Type type)
        {
            // Make sure the Contract is Annotated
            var contractAttribute = type.GetCustomAttribute <DataEntryContractAttribute>();

            if (contractAttribute == null)
            {
                return(null);
            }

            // Process the Contract Information
            var contract = new DataEntryContract(GetId(type))
            {
                Name          = string.Concat("TriTech ", contractAttribute.ModuleType.GetDescription(), " Default"),
                Description   = GetDescription(type),
                ModuleType    = contractAttribute.ModuleType,
                DataEntryType = contractAttribute.DataEntryType,
                TypeName      = type.FullName
            };

            ProcessContractSections(contract, type);
            return(contract);
        }
예제 #14
0
        private void UpdateMetadata(DataEntryContract source, DataEntryContract destination)
        {
            // Update the Contract Information
            destination.DataEntryType = source.DataEntryType;
            destination.Description   = source.Description;
            destination.Name          = source.Name;
            destination.TypeName      = source.TypeName;

            // Update any matching sections
            var sectionsToUpdate = source.Sections.Where(x => destination.Sections.Any(y => y.Path == x.Path)).ToList();

            sectionsToUpdate.ForEach(sourceSection =>
            {
                var destinationSection = destination.Sections.First(x => x.Path == sourceSection.Path);
                UpdateMetadata(sourceSection, destinationSection);
            });

            // Find Sections that Need to be Added
            var sectionsToAdd = source.Sections.Where(x => destination.Sections.All(y => y.Path != x.Path)).ToList();

            // Add the New Section Metadata
            sectionsToAdd.ForEach(destination.Sections.Add);
        }
예제 #15
0
        public static DataEntryContract GetContractInfo(Type type, string implementation = StateImplementations.Generic)
        {
            if (type == null)
            {
                return(null);
            }

            // Make sure the Contract is Annotated as a Data Entry Contract
            var dataEntryContractAttr = type.GetCustomAttribute <DataEntryContractAttribute>();

            if (dataEntryContractAttr == null)
            {
                return(null);
            }

            // Create the DataEntryContract
            var dataEntryContract = new DataEntryContract(GetId(type))
            {
                // Default Name
                Name = GetContractNameForModule(dataEntryContractAttr.ModuleType),
                // Description
                Description = GetDescription(type),
                // Module Type
                ModuleType = dataEntryContractAttr.ModuleType,
                // Report/Summary
                DataEntryType = dataEntryContractAttr.DataEntryType,
                // Type Name
                TypeName = type.FullName
            };

            // Process the Properties of the type attributed as Sections.
            ProcessDataContractSections(dataEntryContract, type, implementation);

            // Return the DataEntryContract
            return(dataEntryContract);
        }