public TermReturn GetTerm(int termId, DictionaryType dictionary, Language language, AudienceType audience) { log.DebugFormat("Enter GetTerm( {0}, {1}, {2}, {3}).", termId, dictionary, language, audience); TermReturn ret = null; try { InputValidator.ValidateGetTerm(termId, dictionary, language, audience); DictionaryManager mgr = new DictionaryManager(); ret = mgr.GetTerm(termId, dictionary, language, audience, API_VERSION); } // If there was a problem with the inputs for this request, fail with // an HTTP status message and an explanation. catch (DictionaryValidationException ex) { WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.SetStatusAsNotFound(ex.Message); ret = new TermReturn() { Meta = new TermReturnMeta() { Messages = new string[] { ex.Message } } }; } log.Debug("Successfully retrieved a term."); return(ret); }
/// <summary> /// Infrastructure for turning the DataTable returned for one of the GetTerm family of query /// methods into a TermReturn object. /// </summary> /// <param name="termId">The ID of the Term which was retrieved</param> /// <param name="language">The Term's desired language. /// Supported values are: /// en - English /// es - Spanish /// </param> /// <param name="audience">The Term's desired audience. /// Supported values are: /// Patient /// HealthProfessional /// </param> /// <returns>A data structure containing both meta data about the request and a string containing a JSON representation /// of the particular definition identified by the inputs to the method. /// </returns> private TermReturn GetTermCommon(DataTable dtTerm, int termId, Language language, AudienceType audience) { List <String> messages = new List <string>(); String term = string.Empty; // Normal, found 1 match. int resultCount = dtTerm.Rows.Count; if (resultCount == 1) { log.Debug("Found 1 result."); messages.Add("OK"); term = dtTerm.Rows[0].Field <string>("object"); term = RewriteMediaFileLocations(term); } // "Normal", found no matches. else if (resultCount == 0) { log.Debug("Found 0 results."); messages.Add("No result found."); term = string.Empty; } // "Odd" case. With multiple matches, return the first one. else // result count must be greater than 1 { log.WarnFormat("Expected to find one result for term {0}, found {1} instead.", termId, resultCount); messages.Add("OK"); term = dtTerm.Rows[0].Field <string>("object"); term = RewriteMediaFileLocations(term); } // Build up the return data structure. TermReturn trmReturn = new TermReturn(); TermReturnMeta meta = new TermReturnMeta(); meta.Language = language.ToString(); meta.Audience = audience.ToString(); meta.Messages = messages.ToArray(); trmReturn.Meta = meta; trmReturn.Term = term; return(trmReturn); }