public string CallDeleteApi(string urlMethod) { string result = ""; HttpResponseMessage response = null; try { HttpClient client = new HttpClient(); string url = _serviceUrl.GetUrl(); response = client.DeleteAsync($"{url}{urlMethod}").Result; response.EnsureSuccessStatusCode(); result = response.Content.ReadAsStringAsync().Result; } catch (HttpRequestException) { if (!string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result)) { throw new HttpRequestException(response.Content.ReadAsStringAsync().Result); } else { throw new HttpRequestException(response.ReasonPhrase); } } return(result); }
/// <summary> /// Obtiene el resultado en formato json de la llamada al api /// </summary> /// <param name="htmlContent">contenido html</param> /// <param name="ocurrence">Posición de la cual hay que mirar</param> /// <returns>resultado de la llamada en formato json</returns> private string Api(string htmlContent, int ocurrence) { int first = htmlContent.IndexOf(DirectivesList.Api, ocurrence); first = first + DirectivesList.Api.Length; int last = htmlContent.IndexOf(DirectivesList.EndDirective, first); string url = htmlContent.Substring(first, last - first).Trim(); TokenBearer token = null; if (url.Contains(_configUrlService.GetUrl()) || url.Contains("{URL_APICARGA}")) { url = url.Replace("{URL_APICARGA}", _configUrlService.GetUrl()); token = _callTokenService.CallTokenCarga(); } else if (url.Contains(_configUrlService.GetUrlDocumentacion()) || url.Contains("{URL_DOCUMENTACION}")) { url = url.Replace("{URL_DOCUMENTACION}", _configUrlService.GetUrlDocumentacion()); token = _callTokenService.CallTokenApiDocumentacion(); } else if (url.Contains(_configUrlCronService.GetUrl()) || url.Contains("{URL_CRON}")) { url = url.Replace("{URL_CRON}", _configUrlCronService.GetUrl()); token = _callTokenService.CallTokenCron(); } string result = _callService.CallGetApi(url, "", token); return(result); }
/// <summary> /// Valida un rdf /// </summary> /// <param name="rdf">Rdf a validar</param> /// <param name="repositoryIdentifier">Repositorio en el que están configurados los shapes para validar</param> public void CallDataValidate(IFormFile rdf, Guid repositoryIdentifier) { string response = _serviceApi.CallPostApi(_serviceUrl.GetUrl(), $"etl/data-validate?repositoryIdentifier={ repositoryIdentifier.ToString()} ", rdf, _token, true); ShapeReportModel shapeReport = JsonConvert.DeserializeObject <ShapeReportModel>(response); if (!shapeReport.conforms && shapeReport.severity == "http://www.w3.org/ns/shacl#Violation") { throw new ValidationException(shapeReport); } }
/// <summary> /// Obtiene un repositorio OAIPMH /// </summary> /// <param name="id">Identificador del repositorio</param> /// <returns>Repositorio OAIPMH</returns> public RepositoryConfigViewModel GetRepositoryConfig(Guid id) { string result = _serviceApi.CallGetApi(_serviceUrl.GetUrl(), $"{_urlRepositoryConfigApi}/{id}", _token); RepositoryConfigViewModel resultObject = JsonConvert.DeserializeObject <RepositoryConfigViewModel>(result); return(resultObject); }
/// <summary> /// Añade una configuración de validación mediante un shape SHACL. /// </summary> /// <param name="newRepositoryConfigView">Configuración de validación a añadir</param> /// <returns>Configuración creada</returns> public ShapeConfigViewModel CreateShapeConfig(ShapeConfigCreateModel newRepositoryConfigView) { Guid guidAdded; string parameters = $"?name={newRepositoryConfigView.Name}&repositoryID={newRepositoryConfigView.RepositoryID}"; string result = _serviceApi.CallPostApi(_serviceUrl.GetUrl(), $"{_urlShapeConfigApi}{parameters}", newRepositoryConfigView.ShapeFile, _token, true); result = JsonConvert.DeserializeObject <string>(result); Guid.TryParse(result, out guidAdded); result = _serviceApi.CallGetApi(_serviceUrl.GetUrl(), $"{_urlShapeConfigApi}/{guidAdded}", _token); ShapeConfigViewModel resultObject = JsonConvert.DeserializeObject <ShapeConfigViewModel>(result); return(resultObject); }