Exemple #1
0
        public IActionResult GetThesaurus(
            [FromRoute] string database,
            [FromRoute] string id,
            [FromQuery] bool emptyIfNotFound)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            Thesaurus thesaurus = repository.GetThesaurus(id);

            if (thesaurus == null)
            {
                return(emptyIfNotFound
                    ? Ok(new ThesaurusModel
                {
                    Id = id,
                    Language = "en",
                    Entries = Array.Empty <ThesaurusEntry>()
                })
                    : (IActionResult)NotFound());
            }

            ThesaurusModel model = new ThesaurusModel
            {
                Id       = thesaurus.Id,
                Language = thesaurus.GetLanguage(),
                Entries  = thesaurus.GetEntries().ToArray()
            };

            return(Ok(model));
        }
Exemple #2
0
        public ActionResult <Dictionary <string, ThesaurusModel> > GetThesauri(
            [FromRoute] string database,
            [FromRoute] string ids,
            [FromQuery] bool purgeIds)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            Dictionary <string, ThesaurusModel> dct =
                new Dictionary <string, ThesaurusModel>();

            foreach (string id in (ids ?? "")
                     .Split(',', StringSplitOptions.RemoveEmptyEntries)
                     .Distinct())
            {
                Thesaurus thesaurus = repository.GetThesaurus(id);
                if (thesaurus == null)
                {
                    continue;
                }
                dct[purgeIds ? PurgeThesaurusId(id) : id] = new ThesaurusModel
                {
                    Id       = thesaurus.Id,
                    Language = thesaurus.GetLanguage(),
                    Entries  = thesaurus.GetEntries().ToArray()
                };
            }
            return(Ok(dct));
        }
Exemple #3
0
        /// <summary>
        /// Create a thesaurus for a community
        /// </summary>
        /// <param name="thesaurusXml">Thesaurus to create</param>
        public void CreateThesaurus(string thesaurusXml)
        {
            try
            {
                string url = $"{ApiUrl}/community/create-thesaurus";

                ThesaurusModel model = new ThesaurusModel()
                {
                    community_short_name = CommunityShortName, thesaurus = thesaurusXml
                };

                WebRequestPostWithJsonObject(url, model);

                Log.Debug($"Thesaurus created in {CommunityShortName}");
            }
            catch (Exception ex)
            {
                Log.Error($"Error creating thesaurus {thesaurusXml} in {CommunityShortName}: \r\n {ex.Message}");
                throw;
            }
        }