Esempio n. 1
0
        /// <summary>
        /// Just download - doesn't record the fact like SourcesController.Download() does.
        /// </summary>
        /// <param name="id"></param>
        public ActionResult Download(int id)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null && dto.FileSize > 0)
            {
                if (((PrfPrincipal)User).CanAccess(dto, this.sourceTasks.GetSourceAuthors(id).ToArray(), this.sourceTasks.GetSourceOwners(id).ToArray()) && !dto.IsReadOnly)
                {
                    string contentType = dto.GetDTOFileExtension();
                    Stream stream      = this.sourceTasks.GetSourceData(id, dto.HasOcrText);
                    return(new FileStreamResult(stream, contentType)
                    {
                        FileDownloadName = dto.GetFileDownloadName()
                    });
                }
                else
                {
                    return(new HttpUnauthorizedResult());
                }
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Esempio n. 2
0
        public IDictionary <SourceDTO, IList <SourceDTO> > DuplicatesByNameOf(string name)
        {
            // sort duplicates in order of import time
            IList <SourceDTO> duplicates = this.sourceQueries.DuplicatesByNameOf(name);

            // group duplicates by file size, keyed by the first one that was imported
            IDictionary <SourceDTO, IList <SourceDTO> > mergeTargets = new Dictionary <SourceDTO, IList <SourceDTO> >();

            foreach (SourceDTO source in duplicates)
            {
                SourceDTO key = null;
                foreach (KeyValuePair <SourceDTO, IList <SourceDTO> > kvp in mergeTargets)
                {
                    if (source.FileSize == kvp.Key.FileSize)
                    {
                        key = kvp.Key;
                        break;
                    }
                }

                if (key != null)
                {
                    mergeTargets[key].Add(source);
                }
                else
                {
                    mergeTargets[source] = new List <SourceDTO>();
                }
            }

            return(mergeTargets);
        }
Esempio n. 3
0
 public void PopulateSource(SourceDTO s)
 {
     if (s != null)
     {
         this.SourceId   = s.SourceID;
         this.SourceName = s.SourceName;
     }
 }
Esempio n. 4
0
 public virtual bool CanAccess(SourceDTO dto, string[] authors, string[] owners)
 {
     if (dto != null)
     {
         return(this.CanAccess(dto.IsRestricted, dto.UploadedByUserID, authors, owners, dto.IsPublic));
     }
     return(false);
 }
Esempio n. 5
0
        public Int64 GetSourceSize(int sourceId)
        {
            SourceDTO dto = this.GetSourceDTO(sourceId);

            if (dto != null)
            {
                return(dto.FileSize);
            }
            return(0);
        }
Esempio n. 6
0
 public void PopulateSource(SourceDTO s)
 {
     if (s != null)
     {
         this.SourceId           = s.SourceID;
         this.SourceName         = s.SourceName;
         this.SourceArchive      = s.Archive;
         this.SourceIsRestricted = s.IsRestricted;
     }
 }
Esempio n. 7
0
        public JsonNetResult Details(int id, int?adminSourceSearchId)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null)
            {
                if (((PrfPrincipal)User).CanAccess(dto, this.sourceTasks.GetSourceAuthors(id).ToArray(), this.sourceTasks.GetSourceOwners(id).ToArray()))
                {
                    // create AdminReviewedSource if not already exists - necessary for frontend to receive current search terms
                    if (adminSourceSearchId.HasValue)
                    {
                        AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                    }

                    SourceInfoView view = new SourceInfoView(dto);

                    if (AsposeService.WordExtensions.Contains(dto.FileExtension))
                    {
                        try
                        {
                            view.DocumentProperties = this.sourceContentTasks.GetWordDocumentProperties(id);
                        }
                        catch (Exception e)
                        {
                            log.Error("Source ID=" + id + " encountered error retrieving word document properties...", e);
                        }
                    }

                    view.SetAdminReviewedSources(this.sourceAttachmentTasks.GetReviewsForSource(id));
                    view.SetAdminSourceImports(this.sourceAttachmentTasks.GetAdminImportsForSource(id));
                    view.SetPersonSources(this.sourceAttachmentTasks.GetPersonSources(id));
                    view.SetEventSources(this.sourceAttachmentTasks.GetEventSources(id));
                    view.SetUnitSources(this.sourceAttachmentTasks.GetUnitSources(id));
                    view.SetOperationSources(this.sourceAttachmentTasks.GetOperationSources(id));
                    view.SetParentSource(this.sourceAttachmentTasks.GetParentSourceOf(id));
                    view.SetChildSources(this.sourceAttachmentTasks.GetChildSourcesOf(id));
                    view.SetSourceAuthors(this.sourceTasks.GetSourceAuthors(id));
                    view.SetSourceOwners(this.sourceTasks.GetSourceOwners(id));

                    return(JsonNet(view));
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.Forbidden;
                    Response.StatusDescription = "You don't have permission to view this source.";
                    return(JsonNet(Response.StatusDescription));
                }
            }
            else
            {
                Response.StatusCode        = (int)HttpStatusCode.NotFound;
                Response.StatusDescription = "That source doesn't exist.";
                return(JsonNet(Response.StatusDescription));
            }
        }
Esempio n. 8
0
        public ActionResult Rescan(int id)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null)
            {
                this.sourceContentTasks.FindPreviewProblems(new List <SourceDTO>()
                {
                    dto
                });
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        public void replace_owned_entity_when_key_not_matching()
        {
            // GIVEN models
            SourceDTO source = new SourceDTO
            {
                Id    = 1,
                Name  = "dto",
                Owned = new OwnedDTO
                {
                    Id   = 2,
                    Name = "owned_dto"
                }
            };

            TargetEntity target = new TargetEntity
            {
                Id            = 1,
                Name          = "entity",
                ExtraProperty = "extra_prop_not_mapped",
                Owned         = new OwnedEntity
                {
                    Id   = 3,
                    Name = "owned_entity"
                }
            };

            int targetCheck = target.GetHashCode();
            int ownedCheck  = target.Owned.GetHashCode();

            MapperContext context = new MapperContext();

            // WHEN mapped
            TargetEntity mapped = mapper.Map(source, target, context);

            // THEN
            Assert.Equal(targetCheck, mapped.GetHashCode()); // root is merged
            Assert.Equal(1, mapped.Id);
            Assert.Equal("dto", mapped.Name);
            Assert.Equal("extra_prop_not_mapped", mapped.ExtraProperty); // extra property is not overwritten

            Assert.NotNull(mapped.Owned);
            Assert.NotEqual(ownedCheck, target.Owned.GetHashCode()); // owned is replaced
            Assert.Equal(2, mapped.Owned.Id);
            Assert.Equal("owned_dto", mapped.Owned.Name);

            Assert.True(context.TryGetEntry <OwnedEntity>(new EntityKey <int>(2), out MapperContextEntry createdEntry));
            Assert.Equal(MapperActionType.Create, createdEntry.ActionType);

            Assert.True(context.TryGetEntry <OwnedEntity>(new EntityKey <int>(3), out MapperContextEntry deletedEntry));
            Assert.Equal(MapperActionType.Delete, deletedEntry.ActionType);
        }
Esempio n. 10
0
 public virtual object ToJSON(SourceDTO dto)
 {
     return(new
     {
         Id = this.Id,
         EventId = this.Event.Id,
         Source = dto != null ? new
         {
             Id = dto.SourceID,
             Name = dto.SourceName,
             Archive = dto.Archive,
             IsRestricted = dto.IsRestricted
         } : null,
         Reliability = this.Reliability != null?this.Reliability.ToJSON() : null,
                           Commentary = this.Commentary,
                           Notes = this.Notes
     });
 }
Esempio n. 11
0
        public async Task <string> AddSourceAsync(SourceDTO _obj)
        {
            try
            {
                var query = "AddSource";
                var param = new DynamicParameters();
                param.Add("@Source", _obj.sourceName);
                param.Add("@leadId", _obj.leadId);
                param.Add("@createdBy", _obj.createdBy);
                object Result = await Connection.ExecuteScalarAsync <object>(query, param, commandType : CommandType.StoredProcedure, transaction : Transaction);

                return(Result.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 12
0
        public void create_owned_entity_when_target_is_null()
        {
            // GIVEN models
            SourceDTO source = new SourceDTO
            {
                Id    = 1,
                Name  = "dto",
                Owned = new OwnedDTO
                {
                    Id   = 2,
                    Name = "owned_dto"
                }
            };

            TargetEntity target = new TargetEntity
            {
                Id            = 1,
                Name          = "entity",
                ExtraProperty = "extra_prop_not_mapped",
                Owned         = null
            };

            MapperContext context = new MapperContext();

            int targetCheck = target.GetHashCode();

            // WHEN mapped
            TargetEntity mapped = mapper.Map(source, target, context);

            // THEN
            Assert.Equal(targetCheck, mapped.GetHashCode()); // root is merged
            Assert.Equal(1, mapped.Id);
            Assert.Equal("dto", mapped.Name);
            Assert.Equal("extra_prop_not_mapped", mapped.ExtraProperty);
            Assert.NotNull(mapped.Owned);
            Assert.Equal(2, mapped.Owned.Id);
            Assert.Equal("owned_dto", mapped.Owned.Name);

            Assert.True(context.TryGetEntry <OwnedEntity>(new EntityKey <int>(2), out MapperContextEntry entry));
            Assert.Equal(MapperActionType.Create, entry.ActionType);
        }
Esempio n. 13
0
        public ActionResult Download(int id, int?adminSourceSearchId)
        {
            SourceDTO dto = this.sourceTasks.GetSourceDTO(id);

            if (dto != null && dto.FileSize > 0)
            {
                if (((PrfPrincipal)User).CanAccess(dto, this.sourceTasks.GetSourceAuthors(id).ToArray(), this.sourceTasks.GetSourceOwners(id).ToArray()))
                {
                    if (!dto.IsReadOnly)
                    {
                        // record WasDownloaded for this search
                        if (adminSourceSearchId.HasValue)
                        {
                            AdminReviewedSource ars = this.sourceAttachmentTasks.GetOrCreateAdminReviewedSource(id, adminSourceSearchId.Value);
                            ars.WasDownloaded = true;
                        }

                        string contentType = dto.GetDTOFileExtension();
                        Stream stream      = this.sourceTasks.GetSourceData(id, dto.HasOcrText);
                        return(new FileStreamResult(stream, contentType)
                        {
                            FileDownloadName = dto.GetFileDownloadName()
                        });
                    }
                    else
                    {
                        return(new HttpUnauthorizedResult());
                    }
                }
                else
                {
                    return(new HttpUnauthorizedResult());
                }
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Esempio n. 14
0
        public SourceInfoView(SourceDTO dto)
        {
            this.Id                = dto.SourceID;
            this.SourceID          = dto.SourceID;
            this.SourceName        = dto.SourceName;
            this.FullReference     = dto.FullReference;
            this.SourcePath        = dto.SourcePath;
            this.SourceDate        = dto.SourceDate;
            this.FileExtension     = FileUtil.GetExtension(dto.SourceName);
            this.IsRestricted      = dto.IsRestricted;
            this.FileDateTimeStamp = dto.FileDateTimeStamp;
            this.Archive           = dto.Archive;
            this.IsReadOnly        = dto.IsReadOnly;
            this.Notes             = dto.Notes;
            this.IsPublic          = dto.IsPublic;

            this.FileSize         = dto.FileSize;
            this.JhroCaseID       = dto.JhroCaseID;
            this.JhroCaseNumber   = dto.JhroCaseNumber;
            this.HasOcrText       = dto.HasOcrText;
            this.UploadedByUserID = dto.UploadedByUserID;
        }
Esempio n. 15
0
        public IList <SourceDTO> GetExtensionlessSources()
        {
            Source    sourceAlias = null;
            SourceDTO dto         = null;

            return(Session.QueryOver <Source>(() => sourceAlias)
                   .Where(Restrictions.Disjunction()
                          .Add(Restrictions.On(() => sourceAlias.FileExtension).IsNull)
                          .Add(Restrictions.Eq(Projections.SqlFunction("LENGTH", NHibernateUtil.Int32, Projections.Property(() => sourceAlias.FileExtension)), 0))
                          // include sources with no ext in SourceName
                          //.Add(Restrictions.Eq(
                          //    Projections.SqlFunction(
                          //        new StandardSQLFunction("CHARINDEX", NHibernateUtil.Int32),
                          //        NHibernateUtil.Int32,
                          //        Projections.Constant(@"."),
                          //        Projections.Property(() => sourceAlias.SourceName)
                          //    ), 0))
                          )
                   .AndRestrictionOn(() => sourceAlias.FileData).IsNotNull
                   .And(() => !sourceAlias.Archive)
                   .SelectList(list => list
                               .Select(Projections.Property(() => sourceAlias.Id)).WithAlias(() => dto.SourceID)
                               .Select(Projections.Property(() => sourceAlias.SourceName)).WithAlias(() => dto.SourceName)
                               .Select(Projections.Property(() => sourceAlias.SourcePath)).WithAlias(() => dto.SourcePath)
                               .Select(Projections.Property(() => sourceAlias.FullReference)).WithAlias(() => dto.FullReference)
                               .Select(Projections.Property(() => sourceAlias.SourceDate)).WithAlias(() => dto.SourceDate)
                               .Select(Projections.Property(() => sourceAlias.FileDateTimeStamp)).WithAlias(() => dto.FileDateTimeStamp)
                               .Select(Projections.Property(() => sourceAlias.FileExtension)).WithAlias(() => dto.FileExtension)
                               .Select(Projections.Property(() => sourceAlias.IsRestricted)).WithAlias(() => dto.IsRestricted)
                               .Select(Projections.Property(() => sourceAlias.IsReadOnly)).WithAlias(() => dto.IsReadOnly)
                               .Select(Projections.Property(() => sourceAlias.Archive)).WithAlias(() => dto.Archive)
                               .Select(Projections.Property(() => sourceAlias.Notes)).WithAlias(() => dto.Notes)
                               .Select(Projections.Property(() => sourceAlias.IsPublic)).WithAlias(() => dto.IsPublic)
                               )
                   .TransformUsing(Transformers.AliasToBean <SourceDTO>())
                   .List <SourceDTO>());
        }
Esempio n. 16
0
 public SourceDataTableView(SourceDTO dto)
 {
     this.PopulateBaseSourceDTO(dto);
 }
Esempio n. 17
0
        public JsonNetResult DataTables(SourceDataTablesParam p)
        {
            int iTotalRecords = 0;
            IList <SourceDataTableView> aaData = new List <SourceDataTableView>();

            // get or create new AdminSourceSearch for this search
            AdminUser         user = this.userTasks.GetAdminUser(this.User.Identity.Name);
            AdminSourceSearch adminSourceSearch;

            if (p.searchAdminSourceSearchId.HasValue && p.searchAdminSourceSearchId.Value > 0)
            {
                adminSourceSearch = this.sourceAttachmentTasks.GetAdminSourceSearch(p.searchAdminSourceSearchId.Value);
            }
            else
            {
                adminSourceSearch = new AdminSourceSearch(p.searchText);
                adminSourceSearch.SearchedByAdminUser = user;
                adminSourceSearch = this.sourceAttachmentTasks.SaveOrUpdateAdminSourceSearch(adminSourceSearch);
            }

            if (p.searchId.HasValue)
            {
                // bypasses NHibernate OutOfMemoryError, but doesn't populate IsAttached
                SourceDTO dto = this.sourceTasks.GetSourceDTO(p.searchId.Value);

                if (dto != null)
                {
                    aaData.Add(new SourceDataTableView(dto));
                    iTotalRecords = 1;
                    adminSourceSearch.NumOfMatchingSources = 1;
                }
            }
            else
            {
                // get past searches in order to use their relevance ratings
                IList <int> adminSourceSearchIds = this.sourceAttachmentTasks.GetAdminSourceSearchIds(adminSourceSearch);

                IList <SourceSearchResultDTO> sources = null;
                if (((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchAllSources))
                {
                    iTotalRecords = this.sourceTasks.GetSearchTotal(
                        ((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchRestrictedSources),
                        p.searchName,
                        p.searchExtension,
                        adminSourceSearch.FullTextSearchTerm,
                        p.GetStartDate(),
                        p.GetEndDate(),
                        p.authorSearchText);
                    sources = this.sourceTasks.GetPaginatedResults(
                        ((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchRestrictedSources),
                        p.iDisplayStart, p.iDisplayLength,
                        p.searchName,
                        p.searchExtension,
                        adminSourceSearch.FullTextSearchTerm,
                        p.GetStartDate(),
                        p.GetEndDate(),
                        adminSourceSearchIds,
                        p.iSortingCols, p.iSortCol, p.sSortDir,
                        user.Id, p.personId, p.eventId,
                        p.authorSearchText);
                }
                else
                {
                    throw new NotImplementedException();
                }

                foreach (SourceSearchResultDTO x in sources)
                {
                    aaData.Add(new SourceDataTableView(x));
                }

                adminSourceSearch.NumOfMatchingSources = iTotalRecords;
                this.sourceAttachmentTasks.SaveOrUpdateAdminSourceSearch(adminSourceSearch);
            }

            return(JsonNet(new DataTablesSourceData
            {
                iTotalRecords = iTotalRecords,
                iTotalDisplayRecords = iTotalRecords,
                sEcho = p.sEcho,
                aaData = aaData.ToArray(),
                adminSourceSearchId = adminSourceSearch.Id
            }));
        }
 public static ReceiptSource FromDto(SourceDTO receiptSourceDto)
 {
     return(new ReceiptSource(receiptSourceDto.PrimaryId.Value, receiptSourceDto.SecondaryId.Value));
 }