Beispiel #1
0
        private static IList <AuthorityGroup> LoadGroups(IEnumerable <string> groupNames, IPersistenceContext context)
        {
            var where = new AuthorityGroupSearchCriteria();
            where.Name.In(groupNames);

            return(context.GetBroker <IAuthorityGroupBroker>().Find(where));
        }
Beispiel #2
0
        public ListAuthorityGroupsResponse ListAuthorityGroups(ListAuthorityGroupsRequest request)
        {
            var criteria = new AuthorityGroupSearchCriteria();

            criteria.Name.SortAsc(0);
            if (request.DataGroup.HasValue)
            {
                criteria.DataGroup.EqualTo(request.DataGroup.Value);
            }

            var assembler = new AuthorityGroupAssembler();

            if (request.Details.HasValue && request.Details.Value)
            {
                var authorityGroups = CollectionUtils.Map(
                    PersistenceContext.GetBroker <IAuthorityGroupBroker>().Find(criteria, request.Page),
                    (AuthorityGroup authorityGroup) => assembler.CreateAuthorityGroupDetail(authorityGroup));
                return(new ListAuthorityGroupsResponse(authorityGroups));
            }
            else
            {
                var authorityGroups = CollectionUtils.Map(
                    PersistenceContext.GetBroker <IAuthorityGroupBroker>().Find(criteria, request.Page),
                    (AuthorityGroup authorityGroup) => assembler.CreateAuthorityGroupSummary(authorityGroup));
                return(new ListAuthorityGroupsResponse(authorityGroups));
            }
        }
		public ListAuthorityGroupsResponse ListAuthorityGroups(ListAuthorityGroupsRequest request)
		{
			var criteria = new AuthorityGroupSearchCriteria();
			criteria.Name.SortAsc(0);

			if (request.DataGroup.HasValue)
				criteria.DataGroup.EqualTo(request.DataGroup.Value);

			var broker = PersistenceContext.GetBroker<IAuthorityGroupBroker>();
			var assembler = new AuthorityGroupAssembler();
			if (request.Details.HasValue && request.Details.Value)
			{
				var authorityGroups = CollectionUtils.Map(
				 broker.Find(criteria, request.Page),
				 (AuthorityGroup authorityGroup) => assembler.CreateAuthorityGroupDetail(authorityGroup));
				var total = broker.Count(criteria);
				return new ListAuthorityGroupsResponse(authorityGroups, (int)total);
			}
			else
			{
				var authorityGroups = CollectionUtils.Map(
					broker.Find(criteria, request.Page),
					(AuthorityGroup authorityGroup) => assembler.CreateAuthorityGroupSummary(authorityGroup));
				var total = broker.Count(criteria);
				return new ListAuthorityGroupsResponse(authorityGroups, (int)total);
			}
		}
Beispiel #4
0
        protected override void Import(UserData data, IUpdateContext context)
        {
            var accountType = string.IsNullOrEmpty(data.AccountType)
                                                                ? UserAccountType.U
                                                                : (UserAccountType)Enum.Parse(typeof(UserAccountType), data.AccountType, true);

            var info = new UserInfo(accountType, data.UserName, data.DisplayName, data.EmailAddress, data.ValidFrom, data.ValidUntil);
            var user = LoadOrCreateUser(info, context);

            user.Enabled = data.Enabled;

            if (data.AuthorityGroups != null)
            {
                foreach (var group in data.AuthorityGroups)
                {
                    var where = new AuthorityGroupSearchCriteria();
                    where.Name.EqualTo(group);

                    var authGroup = CollectionUtils.FirstElement(context.GetBroker <IAuthorityGroupBroker>().Find(where));
                    if (authGroup != null)
                    {
                        user.AuthorityGroups.Add(authGroup);
                    }
                }
            }
        }
Beispiel #5
0
        private AuthorityGroup LoadOrCreateGroup(string name, IPersistenceContext context)
        {
            AuthorityGroup group = null;

            try
            {
                AuthorityGroupSearchCriteria criteria = new AuthorityGroupSearchCriteria();
                criteria.Name.EqualTo(name);

                IAuthorityGroupBroker broker = context.GetBroker <IAuthorityGroupBroker>();
                group = broker.FindOne(criteria);
            }
            catch (EntityNotFoundException)
            {
                group      = new AuthorityGroup();
                group.Name = name;
                context.Lock(group, DirtyState.New);
            }
            return(group);
        }
Beispiel #6
0
        public Guid[] FindDataGroupsByUserName(string userName)
        {
            UserSearchCriteria where = new UserSearchCriteria();
            where.UserName.EqualTo(userName);

            AuthorityGroupSearchCriteria groupWhere = new AuthorityGroupSearchCriteria();
            groupWhere.DataGroup.EqualTo(true);

            // want this to be as fast as possible - use joins and only select the AuthorityToken names
            HqlQuery query = new HqlQuery("select distinct g.OID from User u join u.AuthorityGroups g");
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", where));
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("g", groupWhere));

            // take advantage of query caching if possible
            query.Cacheable = true;

            IList<Guid> oids = ExecuteHql<Guid>(query);
            var result = new Guid[oids.Count];
            oids.CopyTo(result, 0);
            return result;
        }
Beispiel #7
0
        protected override void Import(UserData data, IUpdateContext context)
        {
            UserInfo info = new UserInfo(data.UserName, data.DisplayName, data.EmailAddress, data.ValidFrom, data.ValidUntil);
            User     user = LoadOrCreateUser(info, context);

            user.Enabled = data.Enabled;

            if (data.AuthorityGroups != null)
            {
                foreach (string group in data.AuthorityGroups)
                {
                    AuthorityGroupSearchCriteria where = new AuthorityGroupSearchCriteria();
                    where.Name.EqualTo(group);

                    AuthorityGroup authGroup = CollectionUtils.FirstElement(context.GetBroker <IAuthorityGroupBroker>().Find(where));
                    if (authGroup != null)
                    {
                        user.AuthorityGroups.Add(authGroup);
                    }
                }
            }
        }
Beispiel #8
0
        public Guid[] FindDataGroupsByUserName(string userName)
        {
            UserSearchCriteria where = new UserSearchCriteria();
            where.UserName.EqualTo(userName);

            AuthorityGroupSearchCriteria groupWhere = new AuthorityGroupSearchCriteria();

            groupWhere.DataGroup.EqualTo(true);

            // want this to be as fast as possible - use joins and only select the AuthorityToken names
            HqlQuery query = new HqlQuery("select distinct g.OID from User u join u.AuthorityGroups g");

            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", where));
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("g", groupWhere));

            // take advantage of query caching if possible
            query.Cacheable = true;

            IList <Guid> oids   = ExecuteHql <Guid>(query);
            var          result = new Guid[oids.Count];

            oids.CopyTo(result, 0);
            return(result);
        }
Beispiel #9
0
		private static IList<AuthorityGroup> LoadGroups(IEnumerable<string> groupNames, IPersistenceContext context)
		{
			var where = new AuthorityGroupSearchCriteria();
			where.Name.In(groupNames);

			return context.GetBroker<IAuthorityGroupBroker>().Find(where);
		}
 protected override IList <AuthorityGroup> GetItemsForExport(IReadContext context, int firstRow, int maxRows)
 {
     var where = new AuthorityGroupSearchCriteria();
     where.Name.SortAsc(0);
     return(context.GetBroker <IAuthorityGroupBroker>().Find(where, new SearchResultPage(firstRow, maxRows)));
 }