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).Result; // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("Document doc doesn't have format missing", response.GetError().Message); }
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).Result; // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("File file_1 not found", response.GetError().Message); }
public void Attach(DocumentHandleInfo handleInfo) { if (!InternalState.IsValidHandle(handleInfo.Handle)) { RaiseEvent(new DocumentHandleAttached(handleInfo.Handle)); } }
public CreateDocumentAsCopy( DocumentHandle handle, DocumentDescriptorId descriptorId, DocumentHandleInfo handleInfo) { Handle = handle; DocumentDescriptorId = descriptorId; HandleInfo = handleInfo; }
/// <summary> /// This DocumentDescriptor has the same content of another <see cref="DocumentDescriptor"/> /// this operation mark the current document as owner of the handle of duplicated document /// descriptor /// </summary> /// <param name="otherDocumentDescriptorId"></param> /// <param name="handle"></param> /// <param name="fileName"></param> public void Deduplicate( DocumentDescriptorId otherDocumentDescriptorId, DocumentHandleInfo handleInfo) { ThrowIfDeleted(String.Format("Deduplicate with {0}", otherDocumentDescriptorId)); RaiseEvent(new DocumentDescriptorHasBeenDeduplicated( otherDocumentDescriptorId, handleInfo)); Attach(handleInfo); }
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; }
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 Create(DocumentHandleInfo handleInfo) { if (InternalState.Created) { if (handleInfo.Equals(InternalState.CreationDocumentHandleInfo)) { //idempotency, already initialized return; } throw new DomainException(this.Id, "Already created"); } RaiseEvent(new DocumentDescriptorCreated(InternalState.BlobId, handleInfo)); Attach(handleInfo); }
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).Result; // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("Document doc not found", response.GetError().Message); }
public void Initialize( BlobId blobId, DocumentHandleInfo handleInfo, FileHash hash, String fileName) { ThrowIfDeleted(String.Format("Initialize with blob {0} and fileName {1}", blobId, fileName)); if (HasBeenCreated) { throw new DomainException(Id, "Already initialized"); } RaiseEvent(new DocumentDescriptorInitialized(blobId, handleInfo, hash)); var knownFormat = DocumentFormatTranslator.GetFormatFromFileName(fileName); if (knownFormat != null) { RaiseEvent(new FormatAddedToDocumentDescriptor(knownFormat, blobId, null)); } }
private void When(DocumentDescriptorCreated e) { CreationDocumentHandleInfo = e.HandleInfo; Created = true; }
protected void SetupDocumentHandle(DocumentHandleInfo handleInfo, DocumentDescriptorId documentId) { _handleWriter .FindOneById(handleInfo.Handle) .Returns(info => new DocumentReadModel(handleInfo.Handle, documentId, handleInfo.FileName)); }
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"); }
protected bool Equals(DocumentHandleInfo other) { return Equals(FileName, other.FileName) && DocumentCustomData.IsEquals(CustomData, other.CustomData) && Equals(Handle, other.Handle); }
protected bool Equals(DocumentHandleInfo other) { return(Equals(FileName, other.FileName) && DocumentCustomData.IsEquals(CustomData, other.CustomData) && Equals(Handle, other.Handle)); }
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 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).Result) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("application/pdf", response.Content.Headers.ContentType.MediaType); } }
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).Result) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("\"A document.docx\"", response.Content.Headers.ContentDisposition.FileName); } }