public void GetShapeByID()
        {
            ShapesConfigMockService shapesConfigMockService = new ShapesConfigMockService();
            ValidationController    validationController    = new ValidationController(shapesConfigMockService);
            List <ShapeConfig>      listaRepositorios       = (List <ShapeConfig>)(((OkObjectResult)validationController.GetShape()).Value);

            if (listaRepositorios.Count > 0)
            {
                ShapeConfig shapeConfig        = listaRepositorios[0];
                ShapeConfig shapeConfigGetByID = (ShapeConfig)(((OkObjectResult)validationController.GetShape(shapeConfig.ShapeConfigID)).Value);
                Assert.True(shapeConfig.Name.Equals(shapeConfigGetByID.Name));
            }
        }
 ///<summary>
 ///Modifica un shape existente
 ///</summary>
 ///<param name="shapeConfig">Shape a modificar con los nuevos valores</param>
 public bool ModifyShapeConfig(ShapeConfig shapeConfig)
 {
     bool modified = false;
     ShapeConfig shapeConfigOriginal = GetShapeConfigById(shapeConfig.ShapeConfigID);
     if(shapeConfigOriginal != null)
     {
         shapeConfigOriginal.Name = shapeConfig.Name;
         shapeConfigOriginal.Shape = shapeConfig.Shape;
         shapeConfigOriginal.RepositoryID = shapeConfig.RepositoryID;
         modified = true;
     }
     return modified;
 }
예제 #3
0
 ///<summary>
 ///Elimina un shape existente
 ///</summary>
 ///<param name="identifier">Identificador del shape a eliminar</param>
 public bool RemoveShapeConfig(Guid identifier)
 {
     try
     {
         ShapeConfig shapeConfig = GetShapeConfigById(identifier);
         if (shapeConfig != null)
         {
             _listShapesConfig.Remove(shapeConfig);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public IActionResult ModifyShape(Guid shapeConfigID, string name, Guid repositoryID, IFormFile rdfFile)
        {
            ShapeConfig shapeconfig = new ShapeConfig();

            shapeconfig.ShapeConfigID = shapeConfigID;
            shapeconfig.Name          = name;
            shapeconfig.RepositoryID  = repositoryID;
            try
            {
                if (rdfFile != null)
                {
                    shapeconfig.Shape = SparqlUtility.GetTextFromFile(rdfFile);
                    IGraph shapeGraph = new Graph();
                    shapeGraph.LoadFromString(shapeconfig.Shape);
                }
            }
            catch (Exception ex)
            {
                return(Problem(ex.Message));
            }
            if (!_shapeConfigService.GetShapesConfigs().Exists(x => x.ShapeConfigID == shapeConfigID))
            {
                return(BadRequest(new ErrorExample {
                    Error = $"Comprueba si el shape config con id {shapeconfig.ShapeConfigID} existe"
                }));
            }
            try
            {
                bool modified = _shapeConfigService.ModifyShapeConfig(shapeconfig);
                if (modified)
                {
                    return(Ok($"La configuración del shape {shapeconfig.ShapeConfigID} ha sido modificada"));
                }
                else
                {
                    return(BadRequest(new ErrorExample {
                        Error = $"Se ha producido un error al modificar el Shape"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorExample {
                    Error = $"Se ha producido un error al modificar el Shape " + ex.Message
                }));
            }
        }
예제 #5
0
 ///<summary>
 ///Elimina un shape existente
 ///</summary>
 ///<param name="identifier">Identificador del shape a eliminar</param>
 public bool RemoveShapeConfig(Guid identifier)
 {
     try
     {
         ShapeConfig shapeConfig = GetShapeConfigById(identifier);
         if (shapeConfig != null)
         {
             _context.Entry(shapeConfig).State = EntityState.Deleted;
             _context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #6
0
        ///<summary>
        ///Modifica un shape existente
        ///</summary>
        ///<param name="shapeConfig">Shape a modificar con los nuevos valores</param>
        public bool ModifyShapeConfig(ShapeConfig shapeConfig)
        {
            bool        modified            = false;
            ShapeConfig shapeConfigOriginal = GetShapeConfigById(shapeConfig.ShapeConfigID);

            if (shapeConfigOriginal != null)
            {
                shapeConfigOriginal.Name = shapeConfig.Name;
                if (shapeConfig.Shape != null)
                {
                    shapeConfigOriginal.Shape = shapeConfig.Shape;
                }
                shapeConfigOriginal.RepositoryID = shapeConfig.RepositoryID;
                _context.SaveChanges();
                modified = true;
            }
            return(modified);
        }
예제 #7
0
        private async void Canvas_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (!(ModifyShape.IsChecked ?? false))
            {
                var   p        = e.GetCurrentPoint(Canvas);
                Shape newShape = CreateShapeAtLocation(p.Position.X, p.Position.Y);
                ShapeConfig.BindShapeForModification(newShape, true);
            }
            else
            {
                Shape s = e.OriginalSource as Shape;
                if (s == null)
                {
                    var dialog = new MessageDialog("A shape has to be selected to modify...");
                    await dialog.ShowAsync();

                    return;
                }
                this.ShapeConfig.BindShapeForModification(s);
            }
        }
        public void ModifyConfigShape()
        {
            ShapesConfigMockService shapesConfigMockService = new ShapesConfigMockService();
            ValidationController    validationController    = new ValidationController(shapesConfigMockService);
            ShapeConfig             shapeConfig             = ((List <ShapeConfig>)(((OkObjectResult)validationController.GetShape()).Value))[0];

            StringBuilder personShape = new StringBuilder();

            personShape.AppendLine("@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.");
            personShape.AppendLine("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.");
            personShape.AppendLine("@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.");
            personShape.AppendLine("@prefix xml: <http://www.w3.org/XML/1998/namespace>.");
            personShape.AppendLine("@prefix ns: <http://www.w3.org/2003/06/sw-vocab-status/ns#>.");
            personShape.AppendLine("@prefix sh: <http://www.w3.org/ns/shacl#>.");
            personShape.AppendLine("@prefix roh: <http://purl.org/roh#>.");
            personShape.AppendLine("@prefix foaf: <http://purl.org/roh/mirror/foaf#>.");
            personShape.AppendLine("roh:foaf_PersonShape");
            personShape.AppendLine("	a sh:NodeShape ;");
            personShape.AppendLine("	sh:targetClass foaf:Person ;");
            personShape.AppendLine("	sh:property roh:someValuesDataType__foaf__Person__foaf__firstName.");
            personShape.AppendLine("roh:someValuesDataType__foaf__Person__foaf__firstName ");
            personShape.AppendLine("	sh:severity sh:Violation;");
            personShape.AppendLine("	sh:path foaf:firstName;");
            personShape.AppendLine("	sh:qualifiedMinCount  1;");
            personShape.AppendLine("	sh:qualifiedValueShape [");
            personShape.AppendLine("		sh:datatype xsd:string;");
            personShape.AppendLine("	].");
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.Write(personShape.ToString());
            writer.Flush();
            stream.Position = 0;
            var file = new FormFile(stream, 0, stream.Length, null, "rdf.xml");

            validationController.ModifyShape(shapeConfig.ShapeConfigID, shapeConfig.Name, shapeConfig.RepositoryID, file);
            ShapeConfig updatedshapeConfig = (ShapeConfig)((OkObjectResult)validationController.GetShape(shapeConfig.ShapeConfigID)).Value;

            Assert.True(updatedshapeConfig.Shape.Equals(personShape.ToString()));
        }
        public IActionResult AddShape(string name, Guid repositoryID, IFormFile rdfFile)
        {
            ShapeConfig shapeconfig = new ShapeConfig();

            shapeconfig.ShapeConfigID = Guid.NewGuid();
            shapeconfig.Name          = name;
            shapeconfig.RepositoryID  = repositoryID;
            try
            {
                shapeconfig.Shape = SparqlUtility.GetTextFromFile(rdfFile);
                IGraph shapeGraph = new Graph();
                shapeGraph.LoadFromString(shapeconfig.Shape);
            }
            catch (Exception ex)
            {
                return(Problem(ex.Message));
            }

            try
            {
                Guid addedID = _shapeConfigService.AddShapeConfig(shapeconfig);
                if (!addedID.Equals(Guid.Empty))
                {
                    return(Ok(addedID));
                }
                else
                {
                    return(Problem($"Se ha producido un error al añadir el Shape"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorExample {
                    Error = $"Se ha producido un error al añadir el Shape " + ex.Message
                }));
            }
        }