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; } }
/// <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")); }
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); }
/// <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); }
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); }