Exemple #1
0
        public string AssetWhereClauseForRegion(String regionName)
        {
            var locations = _locationManager.FindLocationsOfParentLocation(new PersonGroup {
                Name = regionName
            });
            var hlagGroupedLocations = locations as HlagGroupedLocation[] ?? locations.ToArray();

            if (CollectionExtensions.IsNullOrEmpty(hlagGroupedLocations))
            {
                Log.WarnFormat("no locations found for region {0}, excluding everything from the filter", regionName);
                return("1=0");
            }
            return(AssetWhereClauseFromLocations(hlagGroupedLocations.ToArray()));
        }
Exemple #2
0
        //Implements HAP-838 + HAP-1062
        public string AssetWhereClauseIfRegionSelected()
        {
            var ctx        = _contextLookuper.LookupContext();
            var parameters = ctx.MetadataParameters;
            var sb         = new StringBuilder();

            if (ctx.IsInModule(FunctionalRole.XItc))
            {
                // for xitc we need extra conditions
                sb.Append(_rooR0017WhereClauseProvider.AssetWhereClause());
            }
            else if (!ctx.IsInAnyModule(FunctionalRole.Tom, FunctionalRole.Itom))
            {
                //HAP-838 item 6, except for TOM,ITOM and XITC with WW no one should see these
                sb.Append("asset.status !='{0}'".Fmt(AssetConstants.Decommissioned));
            }


            if (!HlagLocationUtil.ValidateRegionSelectionIsAllowed(ctx, SecurityFacade.CurrentUser()) ||
                !parameters.ContainsKey("region"))
            {
                //no region selected
                return(sb.ToString());
            }

            var parentRegion = parameters["region"];

            try {
                var locations = _locationManager.FindLocationsOfParentLocation(new PersonGroup {
                    Name = parentRegion
                });
                ISet <string> subcustomers = new HashSet <string>();
                foreach (var hlagGroupedLocation in locations)
                {
                    //HAP-1062 --> appending only subcustomers, but disregarding costcenters
                    subcustomers.Add(hlagGroupedLocation.SubCustomer);
                }
                if (!subcustomers.Any())
                {
                    //no subcustomer added to the query
                    return(sb.ToString());
                }

                if (sb.Length != 0)
                {
                    sb.Append(" and ");
                }


                sb.Append(" asset.pluspcustomer in ( ");

                foreach (var subcustomer in subcustomers)
                {
                    sb.Append("'").Append(subcustomer).Append("'").Append(",");
                }
                //removing last , and adding trailing parenthesis
                return(sb.ToString(0, sb.Length - 1) + ")");
            } catch (Exception) {
                Log.WarnFormat("location {0} was not found", parentRegion);
                return(sb.ToString());
            }
        }