public DocumentReadModel(DocumentHandle handle, DocumentDescriptorId documentid, FileNameWithExtension fileName, DocumentCustomData customData) { Handle = handle; DocumentDescriptorId = documentid; FileName = fileName; CustomData = customData; }
/// <summary> /// Upload a file sent in an http request /// </summary> /// <param name="httpContent">request's content</param> /// <returns>Error message or null</returns> private async Task <String> UploadFromHttpContent(HttpContent httpContent) { if (httpContent == null || !httpContent.IsMimeMultipartContent()) { return("Attachment not found!"); } var provider = await httpContent.ReadAsMultipartAsync( new FileStoreMultipartStreamProvider(_blobStore, _configService) ); if (provider.Filename == null) { return("Attachment not found!"); } if (provider.IsInvalidFile) { return(string.Format("Unsupported file {0}", provider.Filename)); } if (provider.FormData["custom-data"] != null) { _customData = JsonConvert.DeserializeObject <DocumentCustomData>(provider.FormData["custom-data"]); } _fileName = provider.Filename; _blobId = provider.BlobId; return(null); }
public void verify_job_created_with_handle_metadata() { var info = new QueueInfo("test", "", "pdf|docx"); QueueHandler sut = new QueueHandler(info, _db); var customData = new DocumentCustomData() { { "test", "value" }, { "complex", 42 }, }; StreamReadModel rm = new StreamReadModel() { Id = 1L, Handle = "FirstHandle", Filename = new FileNameWithExtension("test.docx"), EventType = HandleStreamEventTypes.DocumentHasNewFormat, FormatInfo = new FormatInfo() { PipelineId = new PipelineId("soffice"), DocumentFormat = new DocumentFormat("office"), BlobId = new BlobId("soffice.1") }, DocumentDescriptorId = new DocumentDescriptorId(1), DocumentCustomData = customData, }; sut.Handle(rm, new TenantId("test")); var collection = _db.GetCollection <QueuedJob>("queue.test"); Assert.That(collection.AsQueryable().Single().HandleCustomData, Is.EquivalentTo(customData)); }
/// <summary> /// Upload a file sent in an http request /// </summary> /// <param name="httpContent">request's content</param> /// <returns>Error message or null</returns> private async Task <String> AddFormatFromHttpContent(HttpContent httpContent, DocumentFormat format) { if (httpContent == null || !httpContent.IsMimeMultipartContent()) { return("Attachment not found!"); } var provider = await httpContent.ReadAsMultipartAsync( new FormatStoreMultipartStreamProvider(_blobStore, format) ); if (provider.Filename == null) { return("Attachment not found!"); } if (provider.FormData["custom-data"] != null) { _customData = JsonConvert.DeserializeObject <DocumentCustomData>(provider.FormData["custom-data"]); } _fileName = provider.Filename; _blobId = provider.BlobId; return(null); }
public DocumentHandleInfo( DocumentHandle handle, FileNameWithExtension fileName, DocumentCustomData customData = null ) { Handle = handle; FileName = fileName; CustomData = customData; }
public void UpdateCustomData(DocumentHandle handle, DocumentCustomData customData) { Logger.DebugFormat("UpdateCustomData on handle {0}", handle); var result = _collection.FindOneAndUpdate( Builders <DocumentReadModel> .Filter.Eq(x => x.Handle, handle), Builders <DocumentReadModel> .Update.Set(x => x.CustomData, customData), new FindOneAndUpdateOptions <DocumentReadModel, DocumentReadModel>() { ReturnDocument = ReturnDocument.After }); }
public void update_custom_data() { _writer.Create(_documentHandle); var handleCustomData = new DocumentCustomData() { { "a", "b" } }; _writer.UpdateCustomData(_documentHandle, handleCustomData); var h = _writer.FindOneById(_documentHandle); Assert.NotNull(h.CustomData); Assert.AreEqual("b", (string)h.CustomData["a"]); }
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"); }
private void SetHandleToReturn() { var customData = new DocumentCustomData() { { "handle1", "test" }, { "handle2", new { isComplex = true, theTruth = 42 } }, }; handle = new DocumentReadModel( new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new FileNameWithExtension("test.txt"), customData ); _handleWriter .FindOneById(Arg.Any <DocumentHandle>()) .Returns(handle); IBlobDescriptor stub = Substitute.For <IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any <BlobId>()).Returns(stub); }
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"); }
/// <summary> /// Upload a file sent in an http request /// </summary> /// <param name="httpContent">request's content</param> /// <returns>Error message or null</returns> private async Task<String> AddFormatFromHttpContent(HttpContent httpContent, DocumentFormat format) { if (httpContent == null || !httpContent.IsMimeMultipartContent()) return "Attachment not found!"; var provider = await httpContent.ReadAsMultipartAsync( new FormatStoreMultipartStreamProvider(_blobStore, format) ); if (provider.Filename == null) return "Attachment not found!"; if (provider.FormData["custom-data"] != null) { _customData = JsonConvert.DeserializeObject<DocumentCustomData>(provider.FormData["custom-data"]); } _fileName = provider.Filename; _blobId = provider.BlobId; return null; }
/// <summary> /// Upload a file sent in an http request /// </summary> /// <param name="httpContent">request's content</param> /// <returns>Error message or null</returns> private async Task<String> UploadFromHttpContent(HttpContent httpContent) { if (httpContent == null || !httpContent.IsMimeMultipartContent()) return "Attachment not found!"; var provider = await httpContent.ReadAsMultipartAsync( new FileStoreMultipartStreamProvider(_blobStore, _configService) ); if (provider.Filename == null) return "Attachment not found!"; if (provider.IsInvalidFile) return string.Format("Unsupported file {0}", provider.Filename); if (provider.FormData["custom-data"] != null) { _customData = JsonConvert.DeserializeObject<DocumentCustomData>(provider.FormData["custom-data"]); } _fileName = provider.Filename; _blobId = provider.BlobId; return null; }
protected bool Equals(DocumentHandleInfo other) { return(Equals(FileName, other.FileName) && DocumentCustomData.IsEquals(CustomData, other.CustomData) && Equals(Handle, other.Handle)); }
public DocumentCustomDataSet(DocumentHandle handle, DocumentCustomData customData) { Handle = handle; CustomData = customData; }
public void SetCustomData(DocumentCustomData data) { this.CustomData = data; }
public void UpdateCustomData(DocumentHandle handle, DocumentCustomData customData) { Logger.DebugFormat("UpdateCustomData on handle {0}", handle); var result = _collection.FindOneAndUpdate( Builders<DocumentReadModel>.Filter.Eq(x => x.Handle, handle), Builders<DocumentReadModel>.Update.Set(x => x.CustomData, customData), new FindOneAndUpdateOptions<DocumentReadModel, DocumentReadModel>() { ReturnDocument = ReturnDocument.After }); }
public void verify_job_created_with_handle_metadata() { var info = new QueueInfo("test", "", "pdf|docx"); QueueHandler sut = new QueueHandler(info, _db); var customData = new DocumentCustomData() { {"test" , "value"}, {"complex" , 42}, }; StreamReadModel rm = new StreamReadModel() { Id = 1L, Handle = "FirstHandle", Filename = new FileNameWithExtension("test.docx"), EventType = HandleStreamEventTypes.DocumentHasNewFormat, FormatInfo = new FormatInfo() { PipelineId = new PipelineId("soffice"), DocumentFormat = new DocumentFormat("office"), BlobId = new BlobId("soffice.1") }, DocumentDescriptorId = new DocumentDescriptorId(1), DocumentCustomData = customData, }; sut.Handle(rm, new TenantId("test")); var collection = _db.GetCollection<QueuedJob>("queue.test"); Assert.That(collection.AsQueryable().Single().HandleCustomData, Is.EquivalentTo(customData)); }
private void SetHandleToReturn() { var customData = new DocumentCustomData() { {"handle1" , "test"}, {"handle2" , new { isComplex = true, theTruth = 42} }, }; handle = new DocumentReadModel( new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new FileNameWithExtension("test.txt"), customData ); _handleWriter .FindOneById(Arg.Any<DocumentHandle>()) .Returns(handle); IBlobDescriptor stub = Substitute.For<IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any<BlobId>()).Returns(stub); }