コード例 #1
0
        private static Dictionary <ServerEntityKey, AuthorityGroupDetail> LoadAuthorityGroups(out List <AuthorityGroupDetail> otherList)
        {
            Dictionary <ServerEntityKey, AuthorityGroupDetail> dic = new Dictionary <ServerEntityKey, AuthorityGroupDetail>();
            var list = new List <AuthorityGroupDetail>();

            using (var service = new AuthorityRead())
            {
                IList <AuthorityGroupDetail> tokens = service.ListDataAccessAuthorityGroupDetails();
                CollectionUtils.ForEach(tokens, delegate(AuthorityGroupDetail group)
                {
                    DataAccessGroupSelectCriteria select = new DataAccessGroupSelectCriteria();
                    select.AuthorityGroupOID.EqualTo(new ServerEntityKey("AuthorityGroupOID", new Guid(group.AuthorityGroupRef.ToString(false, false))));
                    IDataAccessGroupEntityBroker broker = HttpContextData.Current.ReadContext.GetBroker <IDataAccessGroupEntityBroker>();
                    DataAccessGroup accessGroup         = broker.FindOne(select);
                    if (accessGroup != null)
                    {
                        dic.Add(accessGroup.Key, group);
                    }
                    else
                    {
                        list.Add(group);
                    }
                });
            }

            otherList = list;

            return(dic);
        }
コード例 #2
0
        /// <summary>
        /// Gets a list of authority groups that can access a given partition
        /// </summary>
        /// <param name="partitionKey">The partition</param>
        /// <param name="dataAccessGrupsOnly">True to find data access groups only; False to find all authority groups</param>
        /// <param name="allStudiesGroup">Returns a list of groups that have access to all studies</param>
        /// <returns></returns>
        public IList <AuthorityGroupDetail> GetAuthorityGroupsForPartition(ServerEntityKey partitionKey, bool dataAccessGrupsOnly, out IList <AuthorityGroupDetail> allStudiesGroup)
        {
            using (var service = new AuthorityRead())
            {
                IList <AuthorityGroupDetail> groups = dataAccessGrupsOnly
                                                         ? service.ListDataAccessAuthorityGroupDetails()
                                                         : service.ListAllAuthorityGroupDetails();

                IList <AuthorityGroupDetail> resultGroups = new List <AuthorityGroupDetail>();
                var internalAllStudiesGroup = new List <AuthorityGroupDetail>();

                CollectionUtils.ForEach(
                    groups,
                    delegate(AuthorityGroupDetail group)
                {
                    bool allPartitions = false;
                    bool allStudies    = false;
                    foreach (var token in group.AuthorityTokens)
                    {
                        if (token.Name.Equals(ClearCanvas.Enterprise.Common.AuthorityTokens.DataAccess.AllPartitions))
                        {
                            allPartitions = true;
                        }
                        else if (token.Name.Equals(ClearCanvas.Enterprise.Common.AuthorityTokens.DataAccess.AllStudies))
                        {
                            allStudies = true;
                        }

                        if (allPartitions && allStudies)
                        {
                            break;
                        }
                    }

                    if (allPartitions && allStudies)
                    {
                        internalAllStudiesGroup.Add(group);
                        return;
                    }

                    if (!allPartitions)
                    {
                        using (IReadContext readContext = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                        {
                            var criteria = new ServerPartitionDataAccessSelectCriteria();
                            criteria.ServerPartitionKey.EqualTo(partitionKey);

                            var dataCriteria = new DataAccessGroupSelectCriteria();
                            dataCriteria.AuthorityGroupOID.EqualTo(new ServerEntityKey("AuthorityGroupOID", new Guid(group.AuthorityGroupRef.ToString(false, false))));
                            dataCriteria.ServerPartitionDataAccessRelatedEntityCondition.Exists(criteria);

                            var broker = readContext.GetBroker <IDataAccessGroupEntityBroker>();
                            if (broker.Count(dataCriteria) == 0)
                            {
                                return;
                            }
                        }
                    }

                    if (allStudies)
                    {
                        internalAllStudiesGroup.Add(group);
                        return;
                    }

                    resultGroups.Add(group);
                });

                allStudiesGroup = internalAllStudiesGroup;
                return(resultGroups);
            }
        }