private Grouping GetGrouping(int profileId)
        {
            if (_parameters.GroupIds.Count > 1)
            {
                throw new FingertipsException("Only one group ID at a time allowed");
            }

            var groupId = _parameters.GroupIds.First();

            GroupIdProvider groupIdProvider = new GroupIdProvider(profileReader);
            var grouping = new SingleGroupingProvider(groupDataReader, groupIdProvider)
                .GetGroupingByProfileIdAndGroupIdAndAreaTypeIdAndIndicatorIdAndSexIdAndAgeId(profileId, groupId, _parameters.AreaTypeId,
                    _parameters.IndicatorId, _parameters.SexId, _parameters.AgeId);
            return grouping;
        }
        protected List<DomainData> BuildDomainDataForProfile(int profileId, int childAreaTypeId,
            IList<string> benchmarkAreaCodes)
        {
            var dataList = new List<DomainData>();

            var groupIds = new GroupIdProvider(profileReader).GetGroupIds(profileId);
            var groupMetadataList = groupDataReader.GetGroupMetadataList(groupIds);
            var groupDataRepository = new GroupDataAtDataPointRepository
            {
                AssignAreas = false,
                AssignChildAreaData = false
            };

            var benchmarkAreas = ReaderFactory.GetAreasReader().GetAreasFromCodes(benchmarkAreaCodes);

            foreach (var groupMetadata in groupMetadataList)
            {
                var tableData = NewDomainData();
                var groupId = groupMetadata.Id;
                tableData.DomainTitle = groupMetadata.Name;
                tableData.GroupId = groupId;

                var groupData = groupDataRepository.GetGroupData(AreaCodes.England,
                    childAreaTypeId, profileId, groupId);
                var groupRoots = groupData.GroupRoots;

                foreach (var groupRoot in groupRoots)
                {
                    var metadata = groupData.GetIndicatorMetadataById(groupRoot.IndicatorId);
                    AddIndicatorData(groupRoot, metadata, benchmarkAreas);
                }

                dataList.Add(tableData);
            }

            return dataList;
        }
        public void UploadProfile(int profileId)
        {
            // Ensure a group exists
            var profile = profileReader.GetProfile(profileId);
            var ckanGroup = GetCkanGroup(profile);

            // Ckan parameters
            var groupIdProvider = new GroupIdProvider(profileReader);
            var areaTypeListProvider = new AreaTypeListProvider(groupIdProvider,
                areasReader, groupDataReader);
            var parameters = new ProfileParameters(areaTypeListProvider, profileId, ckanGroup.Name);

            var metadataRepo = IndicatorMetadataRepository.Instance;
            var areaCodesToIgnore = profileReader.GetAreaCodesToIgnore(profileId).AreaCodesIgnoredEverywhere;

            var lookUpManager = new LookUpManager(pholioReader, areasReader,
                parameters.AreaTypeIds, parameters.CategoryTypeIds);

            var groupIds = groupIdProvider.GetGroupIds(profileId);
            foreach (var groupId in groupIds)
            {
                var groupings = groupDataReader.GetGroupingsByGroupId(groupId);

                var metadataCollection = metadataRepo.GetIndicatorMetadataCollection(groupings);
                metadataRepo.RemoveSystemContentFields(metadataCollection.IndicatorMetadata);

                foreach (var grouping in groupings)
                {
                    var indicatorId = grouping.IndicatorId;
                    if (indicatorIdsAlreadyUploaded.Contains(indicatorId) == false)
                    {
                        indicatorIdsAlreadyUploaded.Add(indicatorId);

                        var timeRange = new TimeRange(grouping);

                        var metadata = metadataCollection.GetIndicatorMetadataById(indicatorId);

                        Console.WriteLine("#UPLOADING: [{0}] {1} \"{2}\"",
                            indicatorIdsAlreadyUploaded.Count, indicatorId,
                            metadata.Descriptive[IndicatorMetadataTextColumnNames.Name]
                            );

                        // Create/update package
                        var packageIdProvider = new PackageIdProvider(metadata.IndicatorId);
                        var ckanPackage = _ckanPackageRepository.RetrieveOrGetNew(packageIdProvider);
                        CkanGroup group = _ckanGroupRepository.GetExistingGroup(parameters.CkanGroupName);
                        new CkanPackagePropertySetter()
                            .SetProperties(ckanPackage, group, parameters, metadata, timeRange);
                        var savedPackage = _ckanPackageRepository.CreateOrUpdate(ckanPackage);

                        // Create metadata resource
                        var textMetadataResource = new MetadataResourceBuilder()
                            .GetUnsavedResource(savedPackage.Id, metadata, metadataRepo.IndicatorMetadataTextProperties);

                        // Create data resource
                        var allGroupingsForIndicator = groupings
                            .Where(x => x.IndicatorId == indicatorId).ToList();

                        var sexIds = allGroupingsForIndicator
                            .Select(x => x.SexId).Distinct().ToList();

                        var ageIds = groupDataReader.GetAllAgeIdsForIndicator(indicatorId);
                        var allDataList = new CoreDataListBuilder { GroupDataReader = groupDataReader }
                            .GetData(metadata.YearType, grouping, sexIds, ageIds,
                            parameters.AreaTypeIds, parameters.CategoryTypeIds, areaCodesToIgnore);

                        var dataResource = new CoreDataResourceBuilder(lookUpManager)
                            .GetUnsavedResource(savedPackage.Id, metadata, allDataList);

                        // Upload resources
                        new CkanResourceUploader { CkanApi = ckanApi }.AddResourcesToPackage(
                            savedPackage.Id, textMetadataResource, dataResource);
                    }
                }
            }
        }
 public SingleGroupingProvider(IGroupDataReader groupDataReader, GroupIdProvider groupIdProvider)
 {
     this.groupDataReader = groupDataReader;
     this.groupIdProvider = groupIdProvider;
 }
 private IList<int> GetGroupIds(Mock<ProfileReader> reader, int profileId)
 {
     var provider = new GroupIdProvider(reader.Object);
     return provider.GetGroupIds(profileId); ;
 }
 public void TestGetIdsOfProfileThatExists()
 {
     var groupIds = new GroupIdProvider(ReaderFactory.GetProfileReader())
         .GetGroupIds(ProfileIds.Phof);
     Assert.IsTrue(groupIds.Contains(GroupIds.Phof_WiderDeterminantsOfHealth));
 }
        public Dictionary<string, TrendMarkerResult> GetTrendMarkers(string parent_area_code, int group_id,
            int area_type_id, int indicator_id, int sex_id, int age_id)
        {
            try
            {
                // Create dependencies
                var groupDataReader = ReaderFactory.GetGroupDataReader();
                var trendMarkersProvider = new TrendMarkersProvider(ReaderFactory.GetTrendDataReader(), new TrendMarkerCalculator());
                var areaListProvider = new FilteredChildAreaListProvider(ReaderFactory.GetAreasReader());
                var groupIdProvider = new GroupIdProvider(ReaderFactory.GetProfileReader());
                var singleGroupingProvider = new SingleGroupingProvider(groupDataReader, groupIdProvider);
                var groupMetadataList = groupDataReader.GetGroupMetadataList(new List<int> { group_id });
                var profileId = groupMetadataList.First().ProfileId;

                return new TrendMarkersAction(areaListProvider, trendMarkersProvider, singleGroupingProvider)
                    .GetTrendMarkers(parent_area_code, profileId, group_id, area_type_id, indicator_id, sex_id, age_id);
            }
            catch (Exception ex)
            {
                Log(ex);
                throw;
            }
        }
 private void InitSupportingGroupData(int areaTypeId)
 {
     // Supporting data
     const int profileId = ProfileIds.HealthProfilesSupportingIndicators;
     int supportingGroupId = new GroupIdProvider(profileReader).GetGroupIds(profileId)[0];
     GroupData groupData = new GroupDataAtDataPointRepository
     {
         AssignChildAreaData = false,
         AssignAreas = false
     }.GetGroupData(benchmarkAreaCode,areaTypeId, profileId, supportingGroupId);
     groupRootSelector.SupportingGroupRoots = groupData.GroupRoots;
     indicatorMetadataCollection.AddIndicatorMetadata(groupData.IndicatorMetadata);
 }