private DataAccessGroup FindDataAccessGroup(string oid)
        {
            DataAccessGroupSelectCriteria select = new DataAccessGroupSelectCriteria();

            select.AuthorityGroupOID.EqualTo(new ServerEntityKey("AuthorityGroupOID", new Guid(oid)));
            IDataAccessGroupEntityBroker broker = HttpContextData.Current.ReadContext.GetBroker <IDataAccessGroupEntityBroker>();

            return(broker.FindOne(select));
        }
        public DataAccessGroup FindDataAccessGroup(string oid)
        {
            var select = new DataAccessGroupSelectCriteria();

            select.AuthorityGroupOID.EqualTo(new ServerEntityKey("AuthorityGroupOID", new Guid(oid)));
            var broker = HttpContext.Current.GetSharedPersistentContext().GetBroker <IDataAccessGroupEntityBroker>();

            return(broker.FindOne(select));
        }
Esempio n. 3
0
        public static StudyDataAccessSelectCriteria GetDataAccessSubCriteriaForUser(IPersistenceContext context, IPrincipal user)
        {
            if (user.IsInRole(Macro.Enterprise.Common.AuthorityTokens.DataAccess.AllStudies))
            {
                return(null);
            }

            var principal = user as CustomPrincipal;

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

            string key = GetDataAccessSubCriteriaCacheID(principal);

            // check the cache first
            var subCriteria = Cache.Current[key] as StudyDataAccessSelectCriteria;

            if (subCriteria != null)
            {
                return(subCriteria);
            }


            var oidList = new List <ServerEntityKey>();

            foreach (var oid in principal.Credentials.DataAccessAuthorityGroups)
            {
                oidList.Add(new ServerEntityKey("OID", oid));
            }
            var dataAccessGroupSelectCriteria = new DataAccessGroupSelectCriteria();

            dataAccessGroupSelectCriteria.AuthorityGroupOID.In(oidList);

            IList <DataAccessGroup> groups;
            var broker = context.GetBroker <IDataAccessGroupEntityBroker>();

            groups = broker.Find(dataAccessGroupSelectCriteria);


            var entityList = new List <ServerEntityKey>();

            foreach (DataAccessGroup group in groups)
            {
                entityList.Add(group.Key);
            }

            subCriteria = new StudyDataAccessSelectCriteria();
            subCriteria.DataAccessGroupKey.In(entityList);

            // put into cache for re-use
            Cache.Current[key] = subCriteria;

            return(subCriteria);
        }
        private void LoadAuthorityGroup(IPersistenceContext context)
        {
            lock (_syncLock)
            {
                _mapDataAccessGroupsAuthorityGroups = new Dictionary <DataAccessGroup, ServerEntityKey>();

                IDataAccessGroupEntityBroker  dataAccessBroker = context.GetBroker <IDataAccessGroupEntityBroker>();
                DataAccessGroupSelectCriteria all = new DataAccessGroupSelectCriteria();
                var dataAccessGroups = dataAccessBroker.Find(all);

                foreach (var group in dataAccessGroups)
                {
                    _mapDataAccessGroupsAuthorityGroups.Add(group, group.AuthorityGroupOID);
                }
            }
        }
        /// <summary>
        /// Do the insertion of the AutoRoute.
        /// </summary>
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            var criteria = new DataAccessGroupSelectCriteria();

            criteria.AuthorityGroupOID.EqualTo(new ServerEntityKey("AuthorityGroupOID", _authorityGroupOid));

            var authorityGroup = updateContext.GetBroker <IDataAccessGroupEntityBroker>();

            DataAccessGroup group = authorityGroup.FindOne(criteria);

            if (group == null)
            {
                Platform.Log(LogLevel.Warn,
                             "AuthorityGroupOID '{0}' on partition {1} not in database for GrantAccess request!  Ignoring request.", _authorityGroupOid,
                             _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(
                    AlertCategory.Application, AlertLevel.Warning,
                    SR.AlertComponentDataAccessRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                    SR.AlertDataAccessUnknownAuthorityGroup, _authorityGroupOid, _context.ServerPartition.AeTitle);
                return;
            }


            var entityBroker = updateContext.GetBroker <IStudyDataAccessEntityBroker>();

            var selectStudyDataAccess = new StudyDataAccessSelectCriteria();

            selectStudyDataAccess.DataAccessGroupKey.EqualTo(group.Key);
            selectStudyDataAccess.StudyStorageKey.EqualTo(_context.StudyLocationKey);

            if (entityBroker.Count(selectStudyDataAccess) == 0)
            {
                var insertColumns = new StudyDataAccessUpdateColumns
                {
                    DataAccessGroupKey = group.Key,
                    StudyStorageKey    = _context.StudyLocationKey
                };

                entityBroker.Insert(insertColumns);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Method for processing Study level queries.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public override void Query(DicomAttributeCollection message, ServerQueryResultDelegate del)
        {
            var tagList = new List <uint>();

            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var find = read.GetBroker <IStudyEntityBroker>();

                //TODO (CR May 2010): Should change so that the Partition AE Title is passed in the RetrieveAeTitle tag in the query message.

                var criteria = new StudySelectCriteria();
                if (Partition != null)
                {
                    criteria.ServerPartitionKey.EqualTo(Partition.Key);
                }

                if (!Thread.CurrentPrincipal.IsInRole(Macro.Enterprise.Common.AuthorityTokens.DataAccess.AllStudies))
                {
                    var principal = Thread.CurrentPrincipal as CustomPrincipal;
                    if (principal != null)
                    {
                        var oidList = new List <ServerEntityKey>();
                        foreach (var oid in principal.Credentials.DataAccessAuthorityGroups)
                        {
                            oidList.Add(new ServerEntityKey("OID", oid));
                        }
                        var dataAccessGroupSelectCriteria = new DataAccessGroupSelectCriteria();
                        dataAccessGroupSelectCriteria.AuthorityGroupOID.In(oidList);
                        IList <DataAccessGroup> groups;
                        using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                        {
                            var broker = context.GetBroker <IDataAccessGroupEntityBroker>();
                            groups = broker.Find(dataAccessGroupSelectCriteria);
                        }

                        var entityList = new List <ServerEntityKey>();
                        foreach (DataAccessGroup group in groups)
                        {
                            entityList.Add(group.Key);
                        }

                        var dataAccessSelectCriteria = new StudyDataAccessSelectCriteria();
                        dataAccessSelectCriteria.DataAccessGroupKey.In(entityList);

                        criteria.StudyDataAccessRelatedEntityCondition.Exists(dataAccessSelectCriteria);
                    }
                }



                DicomAttributeCollection data = message;
                foreach (DicomAttribute attrib in message)
                {
                    tagList.Add(attrib.Tag.TagValue);
                    if (!attrib.IsNull)
                    {
                        switch (attrib.Tag.TagValue)
                        {
                        case DicomTags.StudyInstanceUid:
                            QueryHelper.SetStringArrayCondition(criteria.StudyInstanceUid,
                                                                (string[])data[DicomTags.StudyInstanceUid].Values);
                            break;

                        case DicomTags.PatientsName:
                            QueryHelper.SetStringCondition(criteria.PatientsName,
                                                           data[DicomTags.PatientsName].GetString(0, string.Empty));
                            break;

                        case DicomTags.PatientId:
                            QueryHelper.SetStringCondition(criteria.PatientId,
                                                           data[DicomTags.PatientId].GetString(0, string.Empty));
                            break;

                        case DicomTags.PatientsBirthDate:
                            QueryHelper.SetRangeCondition(criteria.PatientsBirthDate,
                                                          data[DicomTags.PatientsBirthDate].GetString(0, string.Empty));
                            break;

                        case DicomTags.PatientsSex:
                            QueryHelper.SetStringCondition(criteria.PatientsSex,
                                                           data[DicomTags.PatientsSex].GetString(0, string.Empty));
                            break;

                        case DicomTags.StudyDate:
                            QueryHelper.SetRangeCondition(criteria.StudyDate,
                                                          data[DicomTags.StudyDate].GetString(0, string.Empty));
                            break;

                        case DicomTags.StudyTime:
                            QueryHelper.SetRangeCondition(criteria.StudyTime,
                                                          data[DicomTags.StudyTime].GetString(0, string.Empty));
                            break;

                        case DicomTags.AccessionNumber:
                            QueryHelper.SetStringCondition(criteria.AccessionNumber,
                                                           data[DicomTags.AccessionNumber].GetString(0, string.Empty));
                            break;

                        case DicomTags.StudyId:
                            QueryHelper.SetStringCondition(criteria.StudyId, data[DicomTags.StudyId].GetString(0, string.Empty));
                            break;

                        case DicomTags.StudyDescription:
                            QueryHelper.SetStringCondition(criteria.StudyDescription,
                                                           data[DicomTags.StudyDescription].GetString(0, string.Empty));
                            break;

                        case DicomTags.ReferringPhysiciansName:
                            QueryHelper.SetStringCondition(criteria.ReferringPhysiciansName,
                                                           data[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty));
                            break;

                        case DicomTags.ModalitiesInStudy:
                            // Specify a subselect on Modality in series
                            var seriesSelect = new SeriesSelectCriteria();
                            QueryHelper.SetStringArrayCondition(seriesSelect.Modality,
                                                                (string[])data[DicomTags.ModalitiesInStudy].Values);
                            criteria.SeriesRelatedEntityCondition.Exists(seriesSelect);
                            break;
                        }
                    }
                }

                // Open another read context, in case additional queries are required.
                using (IReadContext subRead = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                {
                    // First find the Online studies
                    var storageCriteria = new StudyStorageSelectCriteria();
                    storageCriteria.StudyStatusEnum.NotEqualTo(StudyStatusEnum.Nearline);
                    storageCriteria.QueueStudyStateEnum.NotIn(new[]
                    {
                        QueueStudyStateEnum.DeleteScheduled,
                        QueueStudyStateEnum.WebDeleteScheduled,
                        QueueStudyStateEnum.EditScheduled
                    });
                    criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria);

                    find.Find(criteria, delegate(Study row)
                    {
                        var response = new DicomMessage();

                        //TODO (CR May 2010): should the availability be NEARLINE?  The criteria above was for ONLINE studies.
                        PopulateStudy(subRead, response, tagList, row, "NEARLINE");
                        del(response.DataSet);
                    });

                    // Now find the Nearline studies
                    storageCriteria = new StudyStorageSelectCriteria();
                    storageCriteria.StudyStatusEnum.EqualTo(StudyStatusEnum.Nearline);
                    storageCriteria.QueueStudyStateEnum.NotIn(new[]
                    {
                        QueueStudyStateEnum.DeleteScheduled,
                        QueueStudyStateEnum.WebDeleteScheduled,
                        QueueStudyStateEnum.EditScheduled
                    });
                    criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria);

                    find.Find(criteria, delegate(Study row)
                    {
                        var response = new DicomMessage();
                        PopulateStudy(subRead, response, tagList, row, "NEARLINE");
                        del(response.DataSet);
                    });
                }
            }

            return;
        }