/// <summary>
 /// Given a dimension value, retrieve a localized title (if one exists). When
 /// English is the local language, we simply return the dimension value name.
 /// When French title is requested, we check if a localized version exists and
 /// if it does we return it. Otherwise, the default English title is returned.
 /// </summary>
 /// <param name="dimVal">Dimension value</param>
 /// <param name="isFrench">French language flag</param>
 /// <returns>Localized dimension value title</returns>
 public static string GetLocalizedTitle(DimVal dimVal, bool isFrench = false)
 {
     if (isFrench && dimVal.Properties.Contains("localization_fr"))
     {
         return(dimVal.Properties["localization_fr"].ToString());
     }
     return(dimVal.Name);
 }
        private static List <EndecaLinkInfo> GetDimensionValueLinks(long dimensionId, DimVal sectionValue,
                                                                    DimVal dimensionValue = null, bool isFrench = false, bool specifyLanguage = false)
        {
            var linkInfoList = new List <EndecaLinkInfo>();
            var dimValList   = dimensionValue == null
                                 ? new List <DimVal> {
                sectionValue
            }
                                 : new List <DimVal> {
                sectionValue, dimensionValue
            };
            var dimension =
                GetRefinements(new List <long> {
                EndecaSectionId, dimensionId
            }, dimValList, isFrench, specifyLanguage)
                .GetDimension(dimensionId);

            if (dimension != null && dimension.Refinements != null &&
                dimension.Refinements.Count > 0)
            {
                var dimensionRefinements = dimension.Refinements;
                if (dimensionRefinements.Count > 0)
                {
                    foreach (var dimRef in dimensionRefinements)
                    {
                        var dimVal = (DimVal)dimRef;

                        linkInfoList.Add(new EndecaLinkInfo(sectionValue, dimVal));

                        var linkInfoListNew = GetDimensionValueLinks(dimensionId, sectionValue, dimVal, isFrench);
                        if (linkInfoListNew != null && linkInfoListNew.Count > 0)
                        {
                            linkInfoList.AddRange(linkInfoListNew);
                        }
                    }
                }
            }

            return(linkInfoList);
        }
        public IEnumerable <DimVal> ProcessDimVals(DimVal dimFirst, long dimensionId, string idTrail, string breadcrumbTrail, bool appendBreadcrumbTrail, int?indigoParentCategoryId, bool enforceUpdate, DimVal dimSecond = null, bool isFrench = false)
        {
            var result = new List <DimVal>();

            if (string.IsNullOrWhiteSpace(breadcrumbTrail))
            {
                breadcrumbTrail = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(idTrail))
            {
                idTrail = string.Empty;
            }

            DimVal dimensionValue = dimSecond;
            var    sectionValue   = dimFirst;
            var    dimValList     = dimensionValue == null
                             ? new List <DimVal> {
                sectionValue
            }
                             : new List <DimVal> {
                sectionValue, dimensionValue
            };

            var dimension =
                EndecaUtils.GetRefinements(new List <long> {
                EndecaSectionId, dimensionId
            }, dimValList, false, false)
                .GetDimension(dimensionId);

            if (dimension != null && dimension.Refinements != null && dimension.Refinements.Count > 0)
            {
                var dimensionRefinements = dimension.Refinements;
                if (dimensionRefinements.Count > 0)
                {
                    var placeHolderBreadcrumbTrail = breadcrumbTrail;
                    var placeHolderIdTrail         = idTrail;
                    foreach (var dimRef in dimensionRefinements)
                    {
                        var dimVal = (DimVal)dimRef;
                        idTrail         += IdTrailSplitter + dimVal.Id;
                        breadcrumbTrail += BreadcrumbTrailSplitter + dimVal.Name;
                        IIndigoCategory match      = null;
                        var             hasChanged = enforceUpdate;
                        if (appendBreadcrumbTrail)
                        {
                            Log.Debug(idTrail + ":" + breadcrumbTrail);
                            match = _existingIndigoCategories.FirstOrDefault(ic => ic.EndecaBreadcrumbId.Equals(idTrail, StringComparison.OrdinalIgnoreCase));
                            if (match == null)
                            {
                                var indigoCategory = GetIndigoCategory(indigoParentCategoryId, dimVal.Name, dimVal.GetFrenchName(), idTrail, (int)dimVal.Id, breadcrumbTrail, false);
                                match = _indigoCategoryService.Insert(indigoCategory);
                                _newItemCountDelta++;
                            }
                            else
                            {
                                // Check if the name has changed. If so, update this category and its entire branch as the breadcrumb values have changed
                                if (hasChanged ||
                                    !(string.Equals(dimVal.Name, match.Name, StringComparison.OrdinalIgnoreCase) &&
                                      string.Equals(dimVal.GetFrenchName(), match.NameFr, StringComparison.OrdinalIgnoreCase)))
                                {
                                    hasChanged           = true;
                                    match.Name           = dimVal.Name;
                                    match.NameFr         = dimVal.GetFrenchName();
                                    match.BreadcrumbPath = breadcrumbTrail;
                                    match.IsModified     = true;
                                    match.IsDeleted      = false;
                                    match = _indigoCategoryService.Update(match);
                                    _modifiedItemCountDelta++;
                                }
                                else if (match.IsDeleted)
                                {
                                    match.IsDeleted = false;
                                    match           = _indigoCategoryService.Update(match);
                                    _modifiedItemCountDelta++;
                                }
                                else
                                {
                                    _unmodifiedItemCountDelta++;
                                }
                                _existingIndigoCategories.Remove(match);
                            }
                        }

                        result.Add(dimVal);

                        var parentId = (appendBreadcrumbTrail) ? match.IndigoCategoryId : indigoParentCategoryId;

                        var linkInfoListNew = ProcessDimVals(sectionValue, dimensionId, idTrail, breadcrumbTrail, appendBreadcrumbTrail, parentId, hasChanged, dimVal, isFrench).ToList();
                        if (linkInfoListNew.Any())
                        {
                            result.AddRange(linkInfoListNew);
                        }
                        breadcrumbTrail = placeHolderBreadcrumbTrail;
                        idTrail         = placeHolderIdTrail;
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        public static string GetFrenchName(this DimVal dimVal)
        {
            var result = (string)dimVal.Properties["localization_fr"];

            return(result);
        }
 public EndecaLinkInfo(DimVal section, DimVal dimensionValue)
 {
     DimensionValue = dimensionValue;
     SectionValue   = section;
 }