Exemplo n.º 1
0
        public ActionResult GetEditionNote(long projectId, TextFormatEnumContract format)
        {
            var client      = GetBookClient();
            var editionNote = client.GetEditionNoteText(projectId, TextFormatEnumContract.Html);

            return(Json(new { editionNote }, GetJsonSerializerSettings()));
        }
Exemplo n.º 2
0
        public string GetPageText(TextResource textResource, TextFormatEnumContract format)
        {
            var fulltextServiceClient = m_communicationProvider.GetFulltextServiceClient();
            var result = fulltextServiceClient.GetTextResource(textResource.ExternalId, format);

            return(result.PageText);
        }
Exemplo n.º 3
0
        public string GetPageTextFromSearch(TextResource textResource, TextFormatEnumContract format,
                                            SearchPageRequestContract searchRequest)
        {
            var fulltextServiceClient = m_communicationProvider.GetFulltextServiceClient();
            var result = fulltextServiceClient.GetTextResourceFromSearch(textResource.ExternalId, format, searchRequest);

            return(result.PageText);
        }
Exemplo n.º 4
0
        public EditionNoteContract GetLatestEditionNote(long projectId, TextFormatEnumContract format)
        {
            m_authorizationManager.AuthorizeBook(projectId, PermissionFlag.ReadProject);

            var editionNoteResource = m_resourceRepository.InvokeUnitOfWork(x => x.GetLatestEditionNote(projectId));

            return(GetEditionNoteContract(editionNoteResource, format));
        }
Exemplo n.º 5
0
        public TextResourceContract GetTextResource(string textResourceId, [FromQuery] TextFormatEnumContract formatValue)
        {
            var textResource = m_textResourceManager.GetTextResource(textResourceId);

            textResource.PageText = m_textConverter.Convert(textResource.PageText, formatValue);
            textResource.PageText = m_pageWithHtmlTagsCreator.CreatePage(textResource.PageText, formatValue);

            return(textResource);
        }
Exemplo n.º 6
0
        public string CreatePage(string textResourcePageText, TextFormatEnumContract formatValue)
        {
            if (formatValue != TextFormatEnumContract.Html)
            {
                return(textResourcePageText);
            }

            textResourcePageText = ReplaceLineBreaks(textResourcePageText);
            textResourcePageText = AddPageTags(textResourcePageText);

            return(textResourcePageText);
        }
Exemplo n.º 7
0
        public string GetEditionNote(EditionNoteResource editionNoteResource, TextFormatEnumContract format)
        {
            var projectExternalId     = editionNoteResource.Resource.Project.ExternalId;
            var bookVersionExternalId = editionNoteResource.BookVersion.ExternalId;
            var transformation        = GetTransformationOrDefault(format, BookTypeEnum.Edition);

            using (var ssc = m_communicationProvider.GetSearchServiceClient())
            {
                var result = ssc.GetBookEditionNote(projectExternalId, bookVersionExternalId, transformation.Name, transformation.OutputFormat, transformation.ResourceLevel);
                return(result);
            }
        }
Exemplo n.º 8
0
        public string GetHeadwordText(HeadwordResource headwordResource, TextFormatEnumContract format)
        {
            var transformation = GetTransformationOrDefault(format, BookTypeEnum.Dictionary);

            using (var ssc = m_communicationProvider.GetSearchServiceClient())
            {
                var project     = headwordResource.Resource.Project;
                var bookVersion = headwordResource.BookVersion;
                var result      = ssc.GetDictionaryEntryByXmlId(project.ExternalId, bookVersion.ExternalId, headwordResource.ExternalId, transformation.Name, transformation.OutputFormat, transformation.ResourceLevel);
                return(result);
            }
        }
Exemplo n.º 9
0
        public string GetPageTextFromSearch(TextResource textResource, TextFormatEnumContract format,
                                            SearchPageRequestContract searchRequest)
        {
            var transformation = GetTransformationOrDefault(format, BookTypeEnum.Edition);

            using (var ssc = m_communicationProvider.GetSearchServiceClient())
            {
                var project     = textResource.Resource.Project;
                var bookVersion = textResource.BookVersion;
                var result      = ssc.GetEditionPageFromSearch(searchRequest.ConditionConjunction, project.ExternalId, bookVersion.ExternalId, textResource.ExternalId, transformation.Name, transformation.OutputFormat, transformation.ResourceLevel);
                return(result);
            }
        }
Exemplo n.º 10
0
        public string GetPageText(TextResource textResource, TextFormatEnumContract format)
        {
            var transformation = GetTransformationOrDefault(format, BookTypeEnum.Edition);

            using (var ssc = m_communicationProvider.GetSearchServiceClient())
            {
                var project     = textResource.Resource.Project;
                var bookVersion = textResource.BookVersion;
                //var result = ssc.GetBookPageByXmlId(project.ExternalId, bookVersion.ExternalId, textResource.ExternalId, "pageToHtml.xsl", outputFormat, ResourceLevelEnumContract.Shared); // TODO dynamically resolve transformation type
                var result = ssc.GetBookPageByXmlId(project.ExternalId, bookVersion.ExternalId, textResource.ExternalId, transformation.Name, transformation.OutputFormat, transformation.ResourceLevel);
                return(result);
            }
        }
Exemplo n.º 11
0
        public string GetPageText(long resourcePageId, TextFormatEnumContract format)
        {
            var textResource = m_resourceRepository.InvokeUnitOfWork(x => x.GetLatestPageText(resourcePageId));

            if (textResource == null)
            {
                return(null);
            }

            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(textResource.Resource.Project.ProjectType);

            return(fulltextStorage.GetPageText(textResource, format));
        }
Exemplo n.º 12
0
        private FullTextContract GetTextResource(TextResource dbResult, TextFormatEnumContract formatValue)
        {
            var result = m_mapper.Map <FullTextContract>(dbResult);

            if (result != null)
            {
                var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(dbResult.Resource.Project.ProjectType);

                var text = fulltextStorage.GetPageText(dbResult, formatValue);
                result.Text = text;
            }

            return(result);
        }
Exemplo n.º 13
0
        private TransformationData GetTransformationOrDefault(TextFormatEnumContract format, BookTypeEnum bookType)
        {
            var outputFormat      = ConvertOutputTextFormat(format);
            var dbTtransformation = m_bookRepository.InvokeUnitOfWork(x => x.GetDefaultTransformation(outputFormat, bookType));
            var transformation    = m_mapper.Map <TransformationData>(dbTtransformation);

            if (transformation == null)
            {
                transformation = new TransformationData
                {
                    Name          = "pageToHtml.xsl",
                    OutputFormat  = OutputFormatEnumContract.Html,
                    ResourceLevel = ResourceLevelEnumContract.Shared,
                };
            }
            return(transformation);
        }
Exemplo n.º 14
0
        private OutputFormatEnum ConvertOutputTextFormat(TextFormatEnumContract format)
        {
            switch (format)
            {
            case TextFormatEnumContract.Raw:
                return(OutputFormatEnum.Xml);

            case TextFormatEnumContract.Html:
                return(OutputFormatEnum.Html);

            case TextFormatEnumContract.Rtf:
                return(OutputFormatEnum.Rtf);

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, null);
            }
        }
Exemplo n.º 15
0
        public string Convert(string textResourceText, TextFormatEnumContract formatValue)
        {
            switch (formatValue)
            {
            case TextFormatEnumContract.Raw:
                return(textResourceText);

            case TextFormatEnumContract.Html:
                return(m_markdownToHtmlConverter.ConvertToHtml(textResourceText));

            case TextFormatEnumContract.Rtf:
                throw new NotSupportedException();

            default:
                throw new ArgumentOutOfRangeException(nameof(formatValue), formatValue, null);
            }
        }
Exemplo n.º 16
0
        public string GetHeadwordText(long headwordId, TextFormatEnumContract format)
        {
            try
            {
                var result = m_client.GetString($"book/headword/{headwordId}/text?format={format}");
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 17
0
        private string ConvertTextFormat(TextFormatEnumContract targetFormat, string text)
        {
            switch (targetFormat)
            {
            case TextFormatEnumContract.Html:
                return(m_markdownConverter.ConvertToHtml(text));

            case TextFormatEnumContract.Raw:
                return(text);

            case TextFormatEnumContract.Rtf:
                throw new MainServiceException(MainServiceErrorCode.UnsupportedFormatType, "Converting text to RTF format is not supported");

            default:
                throw new MainServiceException(MainServiceErrorCode.UnsupportedFormatType, $"Converting text to unknown format {targetFormat} is not supported");
            }
        }
Exemplo n.º 18
0
        public EditionNoteContract GetLatestEditionNote(long projectId, TextFormatEnumContract format)
        {
            try
            {
                var result = m_client.Get <EditionNoteContract>($"project/{projectId}/edition-note?format={format}");
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 19
0
        public string GetPageText(long pageId, TextFormatEnumContract format)
        {
            try
            {
                var result = m_client.GetString($"project/page/{pageId}/text-content?format={format}");
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 20
0
        public TextResourceContract GetTextResource(string resourceId, TextFormatEnumContract formatValue)
        {
            try
            {
                var textResource = m_client.Get <TextResourceContract>($"text/{resourceId}?formatValue={formatValue}");
                return(textResource);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 21
0
        public TextResourceContract GetTextResourceFromSearch(string resourceId, TextFormatEnumContract format, SearchPageRequestContract searchRequest)
        {
            try
            {
                var result = m_client.Post <TextResourceContract>($"text/{resourceId}/search?formatValue={format}", searchRequest);
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 22
0
        public string GetPageTextFromSearch(long pageId, TextFormatEnumContract format,
                                            SearchPageRequestContract request)
        {
            try
            {
                var result = m_client.PostReturnString($"book/page/{pageId}/text/search?format={format}", request);
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Exemplo n.º 23
0
        public string GetHeadwordText(long headwordId, TextFormatEnumContract format, SearchPageRequestContract request = null)
        {
            m_authorizationManager.AuthorizeResource(headwordId);

            var headwordResource = m_bookRepository.InvokeUnitOfWork(x => x.GetHeadwordResource(headwordId, false));

            if (headwordResource == null)
            {
                return(null);
            }

            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(headwordResource.Resource.Project.ProjectType);

            var result = request == null
                ? fulltextStorage.GetHeadwordText(headwordResource, format)
                : fulltextStorage.GetHeadwordTextFromSearch(headwordResource, format, request);

            return(result);
        }
Exemplo n.º 24
0
        public IActionResult GetEditionNote(long projectId, TextFormatEnumContract format)
        {
            var client = GetProjectClient();

            try
            {
                var result = client.GetLatestEditionNote(projectId, format);
                return(Json(result));
            }
            catch (HttpErrorCodeException exception)
            {
                if (exception.StatusCode == HttpStatusCode.NotFound)
                {
                    return(Json(null));
                }

                throw;
            }
        }
Exemplo n.º 25
0
        public string GetPageText(long resourcePageId, TextFormatEnumContract format, SearchPageRequestContract searchRequest = null)
        {
            m_authorizationManager.AuthorizeResource(resourcePageId);

            var textResourceList = m_bookRepository.InvokeUnitOfWork(x => x.GetPageText(resourcePageId));
            var textResource     = textResourceList.FirstOrDefault();

            if (textResource == null)
            {
                return(null);
            }

            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(textResource.Resource.Project.ProjectType);

            var result = searchRequest == null
                ? fulltextStorage.GetPageText(textResource, format)
                : fulltextStorage.GetPageTextFromSearch(textResource, format, searchRequest);

            return(result);
        }
Exemplo n.º 26
0
 public string GetHeadwordTextFromSearch(HeadwordResource headwordResource, TextFormatEnumContract format,
                                         SearchPageRequestContract searchRequest)
 {
     throw new NotSupportedException("Headwords/dictionaries are not supported in ElasticSearch storage.");
 }
Exemplo n.º 27
0
        private EditionNoteContract GetEditionNoteContract(EditionNoteResource editionNoteResource, TextFormatEnumContract format)
        {
            if (editionNoteResource == null)
            {
                return(null);
            }

            var contract = m_mapper.Map <EditionNoteContract>(editionNoteResource);

            if (editionNoteResource.Text != null)
            {
                contract.Text = ConvertTextFormat(format, editionNoteResource.Text);
            }
            else
            {
                var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(editionNoteResource.Resource.Project.ProjectType);
                contract.Text = fulltextStorage.GetEditionNote(editionNoteResource, format);
            }

            return(contract);
        }
Exemplo n.º 28
0
        public FullTextContract GetTextResourceVersion(long textVersionId, TextFormatEnumContract formatValue)
        {
            var dbResult = m_resourceRepository.InvokeUnitOfWork(x => x.GetResourceVersion <TextResource>(textVersionId, true, true));

            return(GetTextResource(dbResult, formatValue));
        }
Exemplo n.º 29
0
        public ActionResult <TextResourceContract> GetSearchTextResource(string textResourceId, [FromQuery] TextFormatEnumContract formatValue, [FromBody] SearchPageRequestContract searchPageRequestContract)
        {
            if (ContainsAnyUnsupportedCriteria(searchPageRequestContract))
            {
                return(BadRequest("Request contains unsupported criteria"));
            }

            var textResource = m_searchManager.SearchOnPageByCriteria(textResourceId, searchPageRequestContract);

            textResource.PageText = m_textConverter.Convert(textResource.PageText, formatValue);
            textResource.PageText = m_pageWithHtmlTagsCreator.CreatePage(textResource.PageText, formatValue);

            return(textResource);
        }
Exemplo n.º 30
0
        public FullTextContract GetTextResourceByPageId(long pageId, TextFormatEnumContract formatValue)
        {
            var dbResult = m_resourceRepository.InvokeUnitOfWork(x => x.GetLatestPageText(pageId));

            return(GetTextResource(dbResult, formatValue));
        }