public void should_download_original_file()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("\"A document.docx\"")
                );

            var format = new DocumentFormat("original");

            var blobId = new BlobId("file_1");
            var doc    = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                blobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore
            .GetDescriptor(blobId)
            .Returns(i => new FsBlobDescriptor(blobId, TestConfig.PathToWordDocument));

            // act
            using (var response = Controller.GetFormat(_tenantId, info.Handle, format))
            {
                // assert
                response.EnsureSuccessStatusCode();
                Assert.AreEqual("\"A document.docx\"", response.Content.Headers.ContentDisposition.FileName);
            }
        }
        public void request_for_missing_format_should_404()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );

            var format = new DocumentFormat("missing");

            var doc = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                new BlobId("file_1")
                );

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            // act
            var response = Controller.GetFormat(_tenantId, info.Handle, format);

            // assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual("Document doc doesn't have format missing", response.GetError().Message);
        }
        public void should_download_pdf_format()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );
            var format    = new DocumentFormat("pdf");
            var pdfBlobId = new BlobId("pdf");

            var doc = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                new BlobId("file_1"));

            doc.AddFormat(new PipelineId("abc"), format, pdfBlobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore.GetDescriptor(pdfBlobId).Returns(i => new FsBlobDescriptor(pdfBlobId, TestConfig.PathToDocumentPdf));

            // act
            using (var response = Controller.GetFormat(_tenantId, info.Handle, format))
            {
                // assert
                response.EnsureSuccessStatusCode();
                Assert.AreEqual("application/pdf", response.Content.Headers.ContentType.MediaType);
            }
        }
Example #4
0
 public LinkDocumentToDocumentDescriptor(
     DocumentDescriptorId documentDescriptorId,
     DocumentHandleInfo handleInfo)
 {
     DocumentDescriptorId = documentDescriptorId;
     HandleInfo           = handleInfo;
 }
        public void when_file_is_not_found_should_return_404()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );
            var format = new DocumentFormat("original");

            var blobId = new BlobId("file_1");
            var doc    = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                blobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore.GetDescriptor(blobId).Returns(i => null);

            // act
            var response = Controller.GetFormat(_tenantId, info.Handle, format);

            // assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual("File file_1 not found", response.GetError().Message);
        }
Example #6
0
 public CreateDocumentAsCopy(
     DocumentHandle handle,
     DocumentDescriptorId descriptorId,
     DocumentHandleInfo handleInfo)
 {
     Handle = handle;
     DocumentDescriptorId = descriptorId;
     HandleInfo           = handleInfo;
 }
 public DocumentDescriptorInitialized(
     BlobId blobId,
     DocumentHandleInfo handleInfo,
     FileHash hash)
 {
     Hash = hash;
     HandleInfo = handleInfo;
     BlobId = blobId;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="documentDescriptorId">The id of the original <see cref="DocumentDescriptorId"/>, this means
 /// that the document with id <param name="otherDocumentDescriptorId"> will be linked to this descriptor</param></param>
 /// <param name="otherDocumentDescriptorId">The id of DocumentDescriptor that is de-duplicated</param>
 /// <param name="otherHandle"></param>
 /// <param name="otherFileName"></param>
 public DeduplicateDocumentDescriptor(
     DocumentDescriptorId documentDescriptorId, 
     DocumentDescriptorId otherDocumentDescriptorId,
     DocumentHandleInfo otherHandleInfo)
     : base(documentDescriptorId)
 {
     OtherDocumentDescriptorId = otherDocumentDescriptorId;
     OtherHandleInfo = otherHandleInfo;
 }
 public DocumentDescriptorInitialized(
     BlobId blobId,
     DocumentHandleInfo handleInfo,
     FileHash hash)
 {
     Hash       = hash;
     HandleInfo = handleInfo;
     BlobId     = blobId;
 }
Example #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="documentDescriptorId">The id of the original <see cref="DocumentDescriptorId"/>, this means
 /// that the document with id <param name="otherDocumentDescriptorId"> will be linked to this descriptor</param></param>
 /// <param name="otherDocumentDescriptorId">The id of DocumentDescriptor that is de-duplicated</param>
 /// <param name="otherHandle"></param>
 /// <param name="otherFileName"></param>
 public DeduplicateDocumentDescriptor(
     DocumentDescriptorId documentDescriptorId,
     DocumentDescriptorId otherDocumentDescriptorId,
     DocumentHandleInfo otherHandleInfo)
     : base(documentDescriptorId)
 {
     OtherDocumentDescriptorId = otherDocumentDescriptorId;
     OtherHandleInfo           = otherHandleInfo;
 }
Example #11
0
        internal void CopyDocument(DocumentHandle copiedHandle)
        {
            ThrowIfDeleted();
            if (InternalState.LinkedDocument == null)
            {
                throw new DomainException((IIdentity)Id, "Cannot copy document not linked to any Document Descriptor");
            }

            var handleInfo = new DocumentHandleInfo(copiedHandle, InternalState.FileName, InternalState.CustomData);

            RaiseEvent(new DocumentCopied(copiedHandle, InternalState.LinkedDocument, handleInfo));
        }
 public InitializeDocumentDescriptorAsAttach(
     DocumentDescriptorId aggregateId, 
     BlobId blobId, 
     DocumentHandleInfo handleInfo,
     DocumentHandle fatherHandle,
     DocumentDescriptorId fatherDocumentDescriptorId,
     FileHash hash, 
     FileNameWithExtension fileName)
     : base(aggregateId, blobId, handleInfo, hash, fileName)
 {
     FatherHandle = fatherHandle;
     FatherDocumentDescriptorId = fatherDocumentDescriptorId;
 }
Example #13
0
 public InitializeDocumentDescriptor(
     DocumentDescriptorId aggregateId,
     BlobId blobId,
     DocumentHandleInfo handleInfo,
     FileHash hash,
     FileNameWithExtension fileName
     ) : base(aggregateId)
 {
     FileName   = fileName;
     Hash       = hash;
     BlobId     = blobId;
     HandleInfo = handleInfo;
 }
Example #14
0
 public InitializeDocumentDescriptorAsAttach(
     DocumentDescriptorId aggregateId,
     BlobId blobId,
     DocumentHandleInfo handleInfo,
     DocumentHandle fatherHandle,
     DocumentDescriptorId fatherDocumentDescriptorId,
     FileHash hash,
     FileNameWithExtension fileName)
     : base(aggregateId, blobId, handleInfo, hash, fileName)
 {
     FatherHandle = fatherHandle;
     FatherDocumentDescriptorId = fatherDocumentDescriptorId;
 }
 public InitializeDocumentDescriptor(
     DocumentDescriptorId aggregateId, 
     BlobId blobId, 
     DocumentHandleInfo handleInfo, 
     FileHash hash, 
     FileNameWithExtension fileName
 ) : base(aggregateId)
 {
     FileName = fileName;
     Hash = hash;
     BlobId = blobId;
     HandleInfo = handleInfo;
 }
        void CreateDocument(int id, string handle, string pathToFile)
        {
            var fname = Path.GetFileName(pathToFile);
            var info  = new DocumentHandleInfo(new DocumentHandle(handle), new FileNameWithExtension(fname));

            _bus.Send(new InitializeDocumentDescriptor(
                          new DocumentDescriptorId(id),
                          _filestore.Upload(DocumentFormats.Original, pathToFile),
                          info,
                          new FileHash("1234abcd"),
                          new FileNameWithExtension("a", "file")
                          ));
            Thread.Sleep(50);
        }
        BlobId AddFormatToDocument(int id, string handle, DocumentFormat format, PipelineId pipelineId, string pathToFile)
        {
            var fname  = Path.GetFileName(pathToFile);
            var info   = new DocumentHandleInfo(new DocumentHandle(handle), new FileNameWithExtension(fname));
            var blobId = _filestore.Upload(format, pathToFile);

            _bus.Send(new AddFormatToDocumentDescriptor(
                          new DocumentDescriptorId(id),
                          format,
                          blobId,
                          pipelineId
                          ));
            Thread.Sleep(50);
            return(blobId);
        }
        public void request_for_missing_document_should_404()
        {
            // arrange
            var documentHandle = new DocumentHandle("doc");
            var info           = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );
            var format = new DocumentFormat("any_format");

            SetupDocumentHandle(info, new DocumentDescriptorId(1));

            // act
            var response = Controller.GetFormat(_tenantId, documentHandle, format);

            // assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual("Document doc not found", response.GetError().Message);
        }
 public DocumentCopied(
     DocumentHandle handle,
     DocumentDescriptorId documentDescriptorId,
     DocumentHandleInfo handleInfo)
 {
     if (handle == null)
     {
         throw new ArgumentNullException("handle");
     }
     if (documentDescriptorId == null)
     {
         throw new ArgumentNullException("documentDescriptorId");
     }
     if (handleInfo == null)
     {
         throw new ArgumentNullException("handleInfo");
     }
     DocumentDescriptorId = documentDescriptorId;
     NewHandle            = handle;
     HandleInfo           = handleInfo;
 }
        private void CreateDocument(
            DocumentDescriptorId documentDescriptorId,
            BlobId blobId,
            DocumentHandle handle,
            DocumentHandle fatherHandle,
            DocumentDescriptorId fatherDocumentDescriptorId,
            FileNameWithExtension fileName,
            DocumentCustomData customData
            )
        {
            var      descriptor = _blobStore.GetDescriptor(blobId);
            ICommand createDocument;
            var      handleInfo = new DocumentHandleInfo(handle, fileName, customData);

            if (fatherHandle == null)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat("Initialize DocumentDescriptor {0} ", documentDescriptorId);
                }

                createDocument = new InitializeDocumentDescriptor(documentDescriptorId, blobId, handleInfo, descriptor.Hash, fileName);
            }
            else
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat("Initialize DocumentDescriptor as attach {0} ", documentDescriptorId);
                }

                createDocument = new InitializeDocumentDescriptorAsAttach(
                    documentDescriptorId,
                    blobId,
                    handleInfo,
                    fatherHandle,
                    fatherDocumentDescriptorId,
                    descriptor.Hash, fileName);
            }
            CommandBus.Send(createDocument, "api");
        }
 public CreateDocumentDescriptor(DocumentDescriptorId aggregateId, DocumentHandleInfo handleInfo)
     : base(aggregateId)
 {
     HandleInfo = handleInfo;
 }
 public DocumentDescriptorCreated(BlobId blobId, DocumentHandleInfo handleInfo)
 {
     BlobId     = blobId;
     HandleInfo = handleInfo;
 }
 public DocumentDescriptorHasBeenDeduplicated(
     DocumentDescriptorId otherDocumentId, DocumentHandleInfo handleInfo)
 {
     HandleInfo = handleInfo;
     DuplicatedDocumentDescriptorId = otherDocumentId;
 }
        internal void UploadFile(String jobFile, DocumentImportTask task)
        {
            String fname = "";

            try
            {
                TenantContext.Enter(task.Tenant);

                if (!task.Uri.IsFile)
                {
                    LogAndThrow("Error importing task file {0}: Uri is not a file: {1}", jobFile, task.Uri);
                }

                fname = task.Uri.LocalPath;

                if (FileHasImportFailureMarker(fname, task.FileTimestamp))
                {
                    return;
                }

                if (!File.Exists(fname))
                {
                    LogAndThrow("Error importing task file {0}: File missing: {1}", jobFile, fname);
                }

                var blobStore         = GetBlobStoreForTenant();
                var identityGenerator = GetIdentityGeneratorForTenant();
                if (blobStore == null || identityGenerator == null)
                {
                    Logger.ErrorFormat("Tenant {1} not found or not configured for file: {1}", task.Tenant, fname);
                    return;
                }

                BlobId blobId;
                if (!String.IsNullOrEmpty(task.FileName))
                {
                    //use the real file name from the task not the name of the file
                    using (FileStream fs = File.Open(fname, FileMode.Open, FileAccess.Read))
                    {
                        blobId = blobStore.Upload(task.Format, new FileNameWithExtension(task.FileName), fs);
                    }
                }
                else
                {
                    //No filename given in task, use name of the blob
                    blobId = blobStore.Upload(task.Format, fname);
                }

                if (task.Format == OriginalFormat)
                {
                    var descriptor = blobStore.GetDescriptor(blobId);
                    var fileName   = new FileNameWithExtension(task.FileName);
                    var handleInfo = new DocumentHandleInfo(task.Handle, fileName, task.CustomData);
                    var documentId = identityGenerator.New <DocumentDescriptorId>();

                    var createDocument = new InitializeDocumentDescriptor(
                        documentId,
                        blobId,
                        handleInfo,
                        descriptor.Hash,
                        fileName
                        );
                    _commandBus.Send(createDocument, "import-from-file");
                }
                else
                {
                    var reader     = _tenantAccessor.Current.Container.Resolve <IDocumentWriter>();
                    var handle     = reader.FindOneById(task.Handle);
                    var documentId = handle.DocumentDescriptorId;

                    var command = new AddFormatToDocumentDescriptor(
                        documentId,
                        task.Format,
                        blobId,
                        new PipelineId("user-content")
                        );
                    _commandBus.Send(command, "import-from-file");
                }

                TaskExecuted(task);
                DeleteImportFailure(fname);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "Job Import Queue - Error importing {0} - {1}", jobFile, ex.Message);
                ImportFailure failure = new ImportFailure()
                {
                    Error     = ex.ToString(),
                    FileName  = fname,
                    Timestamp = DateTime.Now,
                    ImportFileTimestampTicks = task.FileTimestamp.Ticks,
                };
                MarkImportFailure(failure);
            }
            finally
            {
                TenantContext.Exit();
            }
        }
 public DocumentDescriptorHasBeenDeduplicated(
     DocumentDescriptorId otherDocumentId, DocumentHandleInfo handleInfo)
 {
     HandleInfo = handleInfo;
     DuplicatedDocumentDescriptorId = otherDocumentId;
 }
 protected void SetupDocumentHandle(DocumentHandleInfo handleInfo, DocumentDescriptorId documentId)
 {
     _handleWriter
     .FindOneById(handleInfo.Handle)
     .Returns(info => new DocumentReadModel(handleInfo.Handle, documentId, handleInfo.FileName));
 }
 public DocumentDescriptorCreated(BlobId blobId, DocumentHandleInfo handleInfo)
 {
     BlobId = blobId;
     HandleInfo = handleInfo;
 }
 public CreateDocumentDescriptor(DocumentDescriptorId aggregateId, DocumentHandleInfo handleInfo)
     : base(aggregateId)
 {
     HandleInfo = handleInfo;
 }