public ProfileDataWriter(Profile profile)
        {
            _profile = profile;

            // Indicator metadata
            workbook.Worksheets.Add();
        }
 public CkanGroup UpdateGroupWithProfileProperties(Profile profile, CkanGroup ckanGroup)
 {
     SetProperties(ckanGroup, profile);
     if (profile != null)
     {
         ckanGroup = _ckanApi.UpdateGroup(ckanGroup);
     }
     return ckanGroup;
 }
        public void InitNewProfile(Profile profile, bool hasDomains)
        {
            AddOrganisationDetails(profile.Id);

            this.hasDomains = hasDomains;

            ws = workbook.Worksheets.Add();
            ws.Name = sheetNamer.GetSheetName(profile.Name);

            rowIndex = 0;
            AddHeader();
        }
 private CkanGroup GetCkanGroup(string groupId, Profile profile)
 {
     CkanGroup ckanGroup = null;
     int attemptCount = 0;
     while (ckanGroup == null)
     {
         attemptCount++;
         if (attemptCount > 10)
         {
             throw new CkanApiException("Repeated exceptions, reached retry limit");
         }
         ckanGroup = CreateOrRetrieveGroup(groupId, profile);
     }
     return ckanGroup;
 }
        public ProfileDataBuilder(ComparatorMap comparatorMap, Profile profile, List<int> restrictSearchProfileIds,
            IList<ParentArea> parentAreas, IAreaType subnationalAreaType)
        {
            this._comparatorMap = comparatorMap;
            this._profile = profile;
            this._restrictSearchProfileIds = restrictSearchProfileIds;
            this._parentAreas = parentAreas;

            _profileDataWriter = new ProfileDataWriter(profile);

            _profileDataWriter.AddOrganisationDetails(profile.Id);

            _nationalArea = comparatorMap.GetNationalComparator().Area;

            this._subnationalAreaType = subnationalAreaType;
        }
        public Dictionary<ParentArea, IList<Area>> Build(Profile profile, IEnumerable<string> parentAreaCodes, int childAreaTypeId)
        {
            Dictionary<ParentArea, IList<Area>> regionalChildAreas = new Dictionary<ParentArea, IList<Area>>();
            foreach (var parentAreaCode in parentAreaCodes)
            {
                IList<Area> areas = areasReader.GetChildAreas(parentAreaCode, childAreaTypeId);

                // Remove areas to ignore
                IList<string> codesToIgnore = profileReader.GetAreaCodesToIgnore(profile.Id).AreaCodesIgnoredEverywhere;
                if (codesToIgnore.Count > 0)
                {
                    areas = (from a in areas where !codesToIgnore.Contains(a.Code) select a).ToList();
                }

                regionalChildAreas.Add(new ParentArea(parentAreaCode, childAreaTypeId), areas);
            }

            return regionalChildAreas;
        }
        private CkanGroup CreateOrRetrieveGroup(string groupId, Profile profile)
        {
            CkanGroup ckanGroup;
            try
            {
                ckanGroup = _ckanApi.GetGroup(groupId);
                if (ckanGroup == null)
                {
                    // Create new group
                    var unsavedCkanGroup = new CkanGroup
                    {
                        Name = groupId,
                    };
                    SetProperties(unsavedCkanGroup, profile);
                    ckanGroup = _ckanApi.CreateGroup(unsavedCkanGroup);
                }
            }
            catch (Exception ex)
            {
                if (ex is CkanTimeoutException || ex is CkanInternalServerException)
                {
                    ckanGroup = null;

                    if (WaitIfResourceUploadFails)
                    {
                        // Wait 10s before continuing
                        Thread.Sleep(1000 * 10);
                    }
                }
                else
                {
                    throw;
                }
            }
            return ckanGroup;
        }
 private CkanGroup GetCkanGroup(Profile profile)
 {
     CkanGroup ckanGroup = _ckanGroupRepository.CreateOrRetrieveGroup(profile);
     ckanGroup = _ckanGroupRepository.UpdateGroupWithProfileProperties(profile, ckanGroup);
     return ckanGroup;
 }
 public CkanGroup CreateOrRetrieveGroup(Profile profile)
 {
     var groupId = CkanGroup.GetNewName(profile.UrlKey);
     return GetCkanGroup(groupId, profile);
 }
        private void SetProperties(CkanGroup ckanGroup, Profile profile)
        {
            if (profile != null)
            {
                var profileName = profile.Name;
                var description = _contentProvider
                    .GetContentWithHtmlRemoved(profile.Id, ContentKeys.CkanDescription);

                ckanGroup.Title = profileName;
                ckanGroup.Description = description;
            }
        }
 public ProfileDataBuilder(ComparatorMap comparatorMap, Profile profile, List<int> restrictSearchProfileIds,
     IList<int> indicatorIds, IList<ParentArea> parentAreas, IAreaType subnationalAreaType)
     : this(comparatorMap, profile, restrictSearchProfileIds, parentAreas, subnationalAreaType)
 {
     this._indicatorIds = indicatorIds;
 }