public void DataValidate() { ShapesConfigMockService shapesConfigMockService = new ShapesConfigMockService(); RepositoriesConfigMockService repositoriesConfigMockService = new RepositoriesConfigMockService(); ConfigSparql configSparql = new ConfigSparql(); configSparql.Endpoint = ""; etlController etlController = new etlController(repositoriesConfigMockService, shapesConfigMockService, configSparql); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(rdfFile); writer.Flush(); stream.Position = 0; var file = new FormFile(stream, 0, stream.Length, null, "rdf.xml"); ShapeReport report = (ShapeReport)((OkObjectResult)etlController.dataValidate(file, new Guid("390cde26-b39d-41c8-89e0-b87c207d8cf2"))).Value; if (!report.conforms && report.results.Count > 0) { Assert.True(true); } else { Assert.True(false); } }
/// <summary> /// Valida un RDF /// </summary> /// <param name="pRdfFileContent">XML RDF</param> /// <param name="pShapesConfig">Lista de Shapes de validación</param> /// <returns>Lista de triples</returns> public static ShapeReport ValidateRDF(string pRdfFileContent, List <ShapeConfig> pShapesConfig) { //Cargamos la ontología RohGraph ontologyGraph = new RohGraph(); ontologyGraph.LoadFromFile("Config/Ontology/roh-v2.owl"); //Cargamos datos a validar RohGraph dataGraph = new RohGraph(); dataGraph.LoadFromString(pRdfFileContent, new RdfXmlParser()); //Aplicamos inferencias de la ontologia RohRdfsReasoner reasoner = new RohRdfsReasoner(); reasoner.Initialise(ontologyGraph); reasoner.Apply(dataGraph); ShapeReport response = new ShapeReport(); response.conforms = true; response.results = new List <ShapeReport.Result>(); foreach (ShapeConfig shape in pShapesConfig) { IGraph shapeGraph = new Graph(); shapeGraph.LoadFromString(shape.Shape); ShapesGraph shapesGraph = new ShapesGraph(shapeGraph); Report report = shapesGraph.Validate(dataGraph); if (!report.Conforms) { response.conforms = false; response.results.AddRange(report.Results.ToList().Select(x => new ShapeReport.Result() { severity = (x.Severity != null) ? x.Severity.ToString() : null, focusNode = (x.FocusNode != null) ? x.FocusNode.ToString() : null, resultValue = (x.ResultValue != null) ? x.ResultValue.ToString() : null, message = (x.Message != null) ? x.Message.ToString() : null, resultPath = (x.ResultPath != null) ? x.ResultPath.ToString() : null, shapeID = shape.ShapeConfigID, shapeName = shape.Name, sourceShape = (x.SourceShape != null) ? x.SourceShape.ToString() : null, }).ToList()); } } if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Violation")) { response.severity = "http://www.w3.org/ns/shacl#Violation"; } else if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Warning")) { response.severity = "http://www.w3.org/ns/shacl#Warning"; } else if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Info")) { response.severity = "http://www.w3.org/ns/shacl#Info"; } return(response); }
public void DataValidateValidationFileKO() { etlController etlController = new etlController(null, null, null, null, null, null, null, null); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(rdfFile); writer.Flush(); stream.Position = 0; var file = new FormFile(stream, 0, stream.Length, null, "rdf.xml"); var stream2 = new MemoryStream(); var writer2 = new StreamWriter(stream2); writer2.Write(validationFileKO); writer2.Flush(); stream2.Position = 0; var file2 = new FormFile(stream2, 0, stream2.Length, null, "validationKO.xml"); ShapeReport report = (ShapeReport)((OkObjectResult)etlController.dataValidate(file, file2)).Value; if (!report.conforms && report.results.Count > 0) { Assert.True(true); } else { Assert.True(false); } }
///<summary> ///Realizar una llamda Post al método /etl/data-validate para verificar un rdf ///</summary> ///<param name="rdf">contenido en rdf a publicar</param> ///<param name="repositoryIdentifier">Identificador del repositorio</param> public void CallDataValidate(string rdf, Guid repositoryIdentifier) { var bytes = Encoding.UTF8.GetBytes(rdf); MultipartFormDataContent multiContent = new MultipartFormDataContent(); multiContent.Add(new ByteArrayContent(bytes), "rdfFile", "rdfFile.rdf"); string response = CallPostApiFile("etl/data-validate", multiContent, "repositoryIdentifier=" + repositoryIdentifier.ToString()); ShapeReport shapeReport = JsonConvert.DeserializeObject <ShapeReport>(response); if (!shapeReport.conforms && shapeReport.severity == "http://www.w3.org/ns/shacl#Violation") { throw new Exception("Se han producido errores en la validación: " + JsonConvert.SerializeObject(shapeReport)); } }
public IActionResult ExampleError() { etlController etlController = new etlController(null, null, null, null, null, null, null); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(rdfFile); writer.Flush(); stream.Position = 0; var file = new FormFile(stream, 0, stream.Length, null, "rdf.xml"); var stream2 = new MemoryStream(); var writer2 = new StreamWriter(stream2); writer2.Write(validationFileKO); writer2.Flush(); stream2.Position = 0; var file2 = new FormFile(stream2, 0, stream2.Length, null, "validationKO.xml"); ShapeReport report = (ShapeReport)((OkObjectResult)etlController.dataValidate(file, file2)).Value; return(Ok()); }