Ejemplo n.º 1
0
        public async Task Removing_format_from_document()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();

            model.DocumentHandle = handle;
            model.PathToFile     = TestConfig.PathToTextDocument;
            model.CreatedById    = "tika";
            model.Format         = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            //now delete format
            await _documentStoreClient.RemoveFormatFromDocument(handle, new DocumentFormat("tika")).ConfigureAwait(false);

            await UpdateAndWaitAsync().ConfigureAwait(false);

            var formats = await _documentStoreClient.GetFormatsAsync(handle).ConfigureAwait(false);

            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.That(formats, Has.Count.EqualTo(1), "Tika format should be removed from the projection");

            //Uncomment the test if you want to verify that blob id is deleted from a projection
            //Assert.Throws<Exception>(() => _blobStore.GetDescriptor(blobId), "Blob Id for artifact is not deleted");
        }
Ejemplo n.º 2
0
        protected async Task <Boolean> AddFormatToDocumentFromFile(
            string tenantId,
            String jobId,
            Client.Model.DocumentFormat format,
            string pathToFile,
            IDictionary <string, object> customData)
        {
            DocumentStoreServiceClient       client = GetDocumentStoreClient(tenantId);
            AddFormatFromFileToDocumentModel model  = new AddFormatFromFileToDocumentModel
            {
                CreatedById = this.PipelineId,
                JobId       = jobId,
                QueueName   = this.QueueName,
                Format      = format,
                PathToFile  = pathToFile
            };

            var response = await client.AddFormatToDocument(model, customData).ConfigureAwait(false);

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"Job {this.GetType()} Added format {format} to handle with job id {jobId}");
            }

            return(response != null);
        }
Ejemplo n.º 3
0
        public async Task Can_add_new_format_with_api_and_automatic_format_detection()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();

            model.DocumentHandle = handle;
            model.PathToFile     = TestConfig.PathToDocumentPdf;
            model.CreatedById    = "office";
            model.Format         = null; //NO FORMAT, I want document store to be able to detect format
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var formats = await _documentStoreClient.GetFormatsAsync(handle);

            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("pdf")));
            Assert.That(formats, Has.Count.EqualTo(2));
        }
Ejemplo n.º 4
0
        public async Task can_add_new_format_with_api()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();

            model.DocumentHandle = handle;
            model.PathToFile     = TestConfig.PathToTextDocument;
            model.CreatedById    = "tika";
            model.Format         = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();

            var formats = await _documentStoreClient.GetFormatsAsync(handle);

            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("tika")));
            Assert.That(formats, Has.Count.EqualTo(2));
        }
        public void Upload_doc_then_add_format_to_doc()
        {
            _docs.UploadAsync(TestConfig.PathToWordDocument, DocumentHandle.FromString("doc_2")).Wait();
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();

            model.CreatedById    = "tika";
            model.DocumentHandle = DocumentHandle.FromString("doc_2");
            model.PathToFile     = TestConfig.PathToTextDocument;
            model.Format         = new DocumentFormat(DocumentFormats.Tika);
            _docs.AddFormatToDocument(model, null).Wait();
        }
Ejemplo n.º 6
0
        public async Task adding_two_time_same_format_overwrite_older()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();

            model.DocumentHandle = handle;
            model.PathToFile     = TestConfig.PathToTextDocument;
            model.CreatedById    = "tika";
            model.Format         = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();

            //get blobId of the original format
            var    descriptor = _documentDescriptorCollection.FindAll().Single();
            BlobId blobId     = descriptor.Formats
                                .Single(f => f.Key == new DocumentFormat("tika"))
                                .Value.BlobId;

            //now add same format with different content.
            model = new AddFormatFromFileToDocumentModel();
            model.DocumentHandle = handle;
            model.PathToFile     = TestConfig.PathToHtml;
            model.CreatedById    = "tika";
            model.Format         = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();

            var formats = await _documentStoreClient.GetFormatsAsync(handle);

            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("tika")));
            Assert.That(formats, Has.Count.EqualTo(2));

            await CompareDownloadedStreamToFile(TestConfig.PathToHtml, _documentStoreClient.OpenRead(handle, new DocumentFormat("tika")));

            //verify old blob storage was deleted
            //Assert.Throws<Exception>(() => _blobStore.GetDescriptor(blobId), "Blob Id for artifact is not deleted");
        }
Ejemplo n.º 7
0
        public async Task <UploadedDocumentResponse> AddFormatToDocument(
            AddFormatFromFileToDocumentModel model,
            IDictionary <string, object> customData = null)
        {
            using (var sourceStream = File.OpenRead(model.PathToFile))
            {
                using (var client = new HttpClient())
                {
                    using (
                        var content =
                            new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
                    {
                        var fileInfo = new FileInfo(model.PathToFile);
                        content.Add(
                            new StreamContent(sourceStream),
                            "stream",
                            fileInfo.Name
                            );

                        customData = customData ?? new Dictionary <String, Object>();
                        customData.Add(AddFormatToDocumentParameters.CreatedBy, model.CreatedById);
                        customData.Add(AddFormatToDocumentParameters.DocumentHandle, model.DocumentHandle);
                        customData.Add(AddFormatToDocumentParameters.JobId, model.JobId);
                        customData.Add(AddFormatToDocumentParameters.QueueName, model.QueueName);
                        customData.Add(AddFormatToDocumentParameters.Format, model.Format);

                        var stringContent = new StringContent(JsonConvert.SerializeObject(customData));
                        content.Add(stringContent, "custom-data");

                        var modelFormat = model.Format == null ? "null" : model.Format.ToString();
                        var endPoint    = new Uri(_documentStoreUri, Tenant + "/documents/addformat/" + modelFormat);

                        using (var message = await client.PostAsync(endPoint, content).ConfigureAwait(false))
                        {
                            var json = await message.Content.ReadAsStringAsync().ConfigureAwait(false);

                            message.EnsureSuccessStatusCode();
                            return(JsonConvert.DeserializeObject <UploadedDocumentResponse>(json));
                        }
                    }
                }
            }
        }