예제 #1
0
        /// <summary>
        /// Returns a query that shall be used to pick only the available costcenters
        /// </summary>
        /// <param name="subCustomer"></param>
        /// <param name="personId"></param>
        /// <returns></returns>
        private string BuildCostCentersFromMaximo(string subCustomer, string personId)
        {
            var groupNameToQuery = "'" + HapagPersonGroupConstants.BaseHapagLocationPrefix + subCustomer + "%" + "'";
            var results          =
                _maxDAO.FindByNativeQuery(
                    "select p.persongroup,description from PERSONGROUP p left join persongroupview v on p.PERSONGROUP = v.PERSONGROUP " +
                    "where (p.persongroup  like {0} ) and v.PERSONID = {1} and v.groupdefault = 1"
                    .Fmt(groupNameToQuery, "'" + personId + "'"));
            var list = results.Cast <IEnumerable <KeyValuePair <string, object> > >()
                       .Select(r => r.ToDictionary(pair => pair.Key, pair => pair.Value, StringComparer.OrdinalIgnoreCase)).ToList();
            ISet <string> costcenters = new HashSet <string>();

            foreach (var groupsDescription in list)
            {
                var pg = new PersonGroup()
                {
                    Name        = groupsDescription["persongroup"] as string,
                    Description = groupsDescription["description"] as string,
                };
                var supergroup = HlagLocationUtil.IsSuperGroup(pg);
                if (HlagLocationUtil.IsALocationGroup(pg) && !supergroup)
                {
                    costcenters.Add(HlagLocationUtil.GetCostCenter(pg));
                }
            }
            if (!costcenters.Any())
            {
                return("1!=1");
            }


            var groupedLocation = new HlagGroupedLocation(subCustomer, costcenters, false);

            return(groupedLocation.CostCentersForQuery("glaccount"));
        }
예제 #2
0
 public void UpdateCache(IEnumerable <PersonGroup> newPersonGroups)
 {
     while (_starting)
     {
     }
     try {
         _runningJob = true;
         var personGroups = newPersonGroups as PersonGroup[] ?? newPersonGroups.ToArray();
         foreach (var childGroup in personGroups.Where(p => !p.SuperGroup))
         {
             if (HlagLocationsCache.ContainsKey(childGroup))
             {
                 HlagLocationsCache.Remove(childGroup);
             }
             if (!HlagLocationUtil.IsALocationGroup(childGroup))
             {
                 //we don´t need roles or functional roles here
                 continue;
             }
             var location = AddChildGroup(childGroup, false);
         }
         //first let´s populate all groups except for the WW one, the reason is that WW should not exactly get all others as parent,
         // but only the ones which are children of one of the others
         var superGroupsExceptWW = HlagLocationsCache.Keys.Where(p => p.SuperGroup && !p.Name.Equals(HapagPersonGroupConstants.HapagWWGroup));
         var validChildGroups    = PopulateSuperGroups(HlagLocationsCache.Keys, superGroupsExceptWW);
         //now the WW ONE
         var wwSuperGroups = HlagLocationsCache.Keys.Where(p => p.Name.Equals(HapagPersonGroupConstants.HapagWWGroup));
         PopulateSuperGroups(validChildGroups, wwSuperGroups);
         HlagGroupedLocationsCache = new ConcurrentBag <HlagGroupedLocation>();
         AddGroupedLocation(validChildGroups);
     } finally {
         _runningJob = false;
     }
 }
예제 #3
0
        /// <summary>
        ///  returns if the first parameter group is "child" of the second one.
        ///
        ///  If possibleParentGroup is C-HLC-WW-AR-WW, then, all location groups should be considered child of it.
        ///
        ///  Otherwise, only those who match the initial description
        ///
        /// </summary>
        /// <param name="possibleChildGroup"></param>
        /// <param name="possibleParentGroup"></param>
        /// <returns></returns>
        private static bool IsChildLocationGroup(PersonGroup possibleChildGroup, PersonGroup possibleParentGroup)
        {
            if (!HlagLocationUtil.IsALocationGroup(possibleChildGroup))
            {
                return(false);
            }
            if (possibleChildGroup.Description.GetNthIndex('-', 3) == -1)
            {
                //To disable things like INACTIVE from the list
                return(false);
            }
            var descriptionMatches = possibleChildGroup.Description.ToUpper().StartsWith(possibleParentGroup.Description.ToUpper()) && !possibleChildGroup.Description.Equals(possibleParentGroup.Description);

            return((descriptionMatches || possibleParentGroup.Name.Equals(HapagPersonGroupConstants.HapagWWGroup)) && !possibleChildGroup.SuperGroup);
        }
예제 #4
0
        private IEnumerable <HlagLocation> PopulateChildGroups(IEnumerable <PersonGroup> allGroups)
        {
            var result = new List <HlagLocation>();

            foreach (var personGroup in allGroups.Where(g => !g.SuperGroup && HlagLocationUtil.IsALocationGroup(g)))
            {
                var childGroup = AddChildGroup(personGroup, false);
                if (childGroup != null)
                {
                    //the gropus could be renamed to thing like INACTIVE, making it invalid
                    result.Add(childGroup);
                }
            }
            return(result);
        }
예제 #5
0
        private HlagLocation AddChildGroup(PersonGroup personGroup, Boolean fromSuperGroup)
        {
            var costCenter = HlagLocationUtil.GetCostCenter(personGroup);

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

            var hlagLocation = new HlagLocation {
                CostCenter     = costCenter,
                SubCustomer    = HlagLocationUtil.GetSubCustomerId(personGroup),
                FromSuperGroup = fromSuperGroup
            };

            HlagLocationsCache[personGroup] = new HashSet <HlagLocation> {
                hlagLocation
            };
            return(hlagLocation);
        }
예제 #6
0
        public HlagGroupedLocation[] GetLocationsOfUser(InMemoryUser user, bool forceXITCContext = false)
        {
            if (!user.Genericproperties.ContainsKey(HapagPersonGroupConstants.HlagLocationProperty))
            {
                //TODO: investigate this issue
                return(new HlagGroupedLocation[] { });
            }
            var locations = user.Genericproperties[HapagPersonGroupConstants.HlagLocationProperty] as UserHlagLocation;

            Log.DebugFormat("locations of user {0}: {1}", user.Login, locations);
            var ctx = _contextLookuper.LookupContext();

            if (locations == null)
            {
                return(new HlagGroupedLocation[] { });
            }
            //            var groupedLocations = locations.GroupedLocations;
            if (ctx.MetadataParameters.ContainsKey("region") && HlagLocationUtil.ValidateRegionSelectionIsAllowed(ctx, user, forceXITCContext))
            {
                return(HandleSelectedRegion(ctx));
            }


            if (forceXITCContext || ctx.IsInModule(FunctionalRole.XItc))
            {
                if (user.IsWWUser())
                {
                    var hlagGroupedLocations = FindAllLocations().ToArray();
                    Log.DebugFormat("found {0} location entries for R0017", hlagGroupedLocations.Length);
                    return(hlagGroupedLocations);
                }
                var supergroups      = locations.GroupedLocationsFromParent;
                var groupedLocations = supergroups.ToArray();
                Log.DebugFormat("found {0} location entries for R0017", groupedLocations.Length);
                return(groupedLocations);
            }
            var result = locations.DirectGroupedLocations.ToArray();

            Log.DebugFormat("found {0} location entries for R0017", result.Length);
            return(result);
        }
예제 #7
0
        public UserHlagLocation FillUserLocations(InMemoryUser user, Boolean clearUserCache = false)
        {
            while (_runningJob || _starting)
            {
                //waiting for job to complete
            }


            if (clearUserCache)
            {
                user.Genericproperties.Remove(HapagPersonGroupConstants.HlagLocationProperty);
            }

            if (user.Genericproperties.ContainsKey(HapagPersonGroupConstants.HlagLocationProperty))
            {
                return(user.Genericproperties[HapagPersonGroupConstants.HlagLocationProperty] as UserHlagLocation);
            }


            var resultLocations = new List <HlagLocation>();

            foreach (var personGroupAssociation in user.PersonGroups)
            {
                var @group = personGroupAssociation.PersonGroup;
                if (!HlagLocationUtil.IsALocationGroup(@group))
                {
                    continue;
                }
                if (@group.SuperGroup && !user.IsInRole(FunctionalRole.XItc.GetName()))
                {
                    //if not a XITC FR member, we cannot add supergroup roles, like regions and areas
                    continue;
                }
                if (!HlagLocationsCache.ContainsKey(@group))
                {
                    continue;
                }
                var groupLocations = HlagLocationsCache[@group];
                foreach (var groupLocation in groupLocations)
                {
                    resultLocations.Add(groupLocation);
                }
            }
            var groupedLocations             = BuildGroupedLocations(resultLocations);
            var directGroupedLocations       = BuildGroupedLocations(resultLocations.Where(f => !f.FromSuperGroup));
            var groupedLocationsFromParent   = BuildGroupedLocations(resultLocations.Where(f => f.FromSuperGroup));
            var directGroupLocationsNoPrefix = directGroupedLocations.Select(hlagGroupedLocation => new HlagGroupedLocationsNoPrefixDecorator(hlagGroupedLocation));

            var result1 = new UserHlagLocation {
                Locations                      = new HashSet <HlagLocation>(resultLocations),
                GroupedLocations               = groupedLocations,
                DirectGroupedLocations         = directGroupedLocations,
                DirectGroupedLocationsNoPrefix = new HashSet <HlagGroupedLocationsNoPrefixDecorator>(directGroupLocationsNoPrefix),
                GroupedLocationsFromParent     = groupedLocationsFromParent
            };
            var result = result1;

            user.Genericproperties[HapagPersonGroupConstants.HlagLocationProperty] = result;

            if (user.IsInGroup(HapagPersonGroupConstants.XITC) && !user.Genericproperties.ContainsKey(HapagPersonGroupConstants.HlagLocationXITCProperty))
            {
                //HAP-1017 , for XITC we need to fill the list of "sub" locations so that these job plan actions of them become also available
                //TODO: move to a better place...
                var allGroups  = GetLocationsOfUser(user, true);
                var xitcgroups = new HashSet <string>();
                foreach (var hlagGroupedLocation in allGroups)
                {
                    var descriptions = hlagGroupedLocation.GetGroupDescriptions();
                    foreach (var description in descriptions)
                    {
                        xitcgroups.Add(description);
                    }
                }
                user.Genericproperties[HapagPersonGroupConstants.HlagLocationXITCProperty] = xitcgroups;
            }


            return(result);
        }