public void TestDeleteUriStructureOk() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); IsDeleting = true; CreateBackUpConfig(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; if (configJsonHandler.ExistUriStructure("uriPublicationStructure")) { configJsonHandler.DeleteUriStructureInfo("uriPublicationStructure"); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); schemaConfigFileOperations.SaveConfigJson(); UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig(); RestoreBackUpConfig(); configJsonHandler.LoadConfigJson(); IsDeleting = false; Assert.True(oldResourcesClassesCount == uriSchema2.ResourcesClasses.Count + 1 && oldUriStructuresCount == uriSchema2.UriStructures.Count + 1); } else { IsDeleting = false; Assert.True(false); } } catch (Exception) { RestoreBackUpConfig(); IsDeleting = false; } }
public void TestAddUriStructureOk() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); CreateBackUpConfig(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass); schemaConfigFileOperations.SaveConfigJson(); ConfigJsonHandler configJsonHandler2 = new ConfigJsonHandler(); UriStructureGeneral uriSchema2 = configJsonHandler2.GetUrisConfig(); RestoreBackUpConfig(); configJsonHandler2.LoadConfigJson(); Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count); } catch (Exception) { RestoreBackUpConfig(); } }
public async void TestUriPublicationOK() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); var parsedJson = configJsonHandler.GetUrisConfig(); Assert.True(parsedJson != null); }
public void TestAddUriStructureOk() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); schemaConfigOperations.SaveConfigJson(); UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig(); Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count); }
public void TestUriPublicationFail() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); Assert.Throws <ParametersNotConfiguredException>(() => uriFormer.GetURI("publication", queryString)); }
public void TestDeleteUriStructureOk() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; if (configJsonHandler.ExistUriStructure("uriResourceStructure")) { configJsonHandler.DeleteUriStructureInfo("uriResourceStructure"); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); schemaConfigOperations.SaveConfigJson(); UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig(); Assert.True(oldResourcesClassesCount > uriSchema2.ResourcesClasses.Count && oldUriStructuresCount > uriSchema2.UriStructures.Count); } else { Assert.True(false); } }
public void TestUriResearcherOK() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("AcademicDegree", queryString); string uriResultante = "http://graph.um.es/res/academic-degree/123d"; Assert.True(uriResultante.Equals(uri)); }
public void TestUriRdfTypeOK() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("http://purl.org/roh/mirror/vivo#AdvisorRole", queryString, true); string uriResultante = "http://graph.um.es/res/advisor-role/123d"; Assert.True(uriResultante.Equals(uri)); }
static void Main(string[] args) { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); string texto = File.ReadAllText("Config/UrisConfig.json"); UriStructureGeneral uriStructure = JsonConvert.DeserializeObject <UriStructureGeneral>(texto); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(texto); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("AdvisorRole", queryString); Console.WriteLine(uri); }
public void TestDeleteUriStructureNoNameFoundError() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); CreateBackUpConfig(); Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.DeleteUriStructureInfo("badName")); schemaConfigFileOperations.SaveConfigJson(); configJsonHandler.GetUrisConfig(); RestoreBackUpConfig(); } catch (Exception) { RestoreBackUpConfig(); } }
public IActionResult GenerateUri(string resource_class, string identifier) { Dictionary <string, string> queryDictionary = new Dictionary <string, string>(); if (HttpContext != null) { var queryString = HttpContext.Request.Query.ToList(); foreach (var value in queryString) { queryDictionary.Add(value.Key, value.Value.FirstOrDefault()); } } else { queryDictionary.Add(UriComponentsList.Identifier, identifier); } UriFormer uriFormer = new UriFormer(_configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI(resource_class, queryDictionary); return(Ok(uri)); }
public IActionResult GenerateUri(string resource_class, string identifier) { if (!System.Uri.IsWellFormedUriString(identifier, System.UriKind.Relative)) { identifier = HttpUtility.UrlEncode(identifier); } Dictionary <string, string> queryDictionary = new Dictionary <string, string>(); if (HttpContext != null) { var queryString = HttpContext.Request.Query.ToList(); foreach (var value in queryString) { if (value.Key == "identifier") { string valueAux = value.Value.FirstOrDefault(); if (!System.Uri.IsWellFormedUriString(valueAux, System.UriKind.Relative)) { valueAux = HttpUtility.UrlEncode(valueAux); } queryDictionary.Add(value.Key, valueAux); } else { queryDictionary.Add(value.Key, value.Value.FirstOrDefault()); } } } else { queryDictionary.Add(UriComponentsList.Identifier, identifier); } UriFormer uriFormer = new UriFormer(_configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI(resource_class, queryDictionary); return(Ok(uri)); }
public void Apply(OpenApiOperation operation, OperationFilterContext context) { UriStructureGeneral uriStructureGeneral = _configJsonHandler.GetUrisConfig(); if (operation.OperationId != null && operation.OperationId.Equals("GenerateUri")) { foreach (UriStructure structure in uriStructureGeneral.UriStructures) { foreach (Component component in structure.Components) { if (!UriComponentsList.DefaultParameters.Contains(component.UriComponent)) { operation.Parameters.Add(new OpenApiParameter { Name = component.UriComponent, In = ParameterLocation.Query, Required = false }); } } } } }
public bool SaveConfigJson() { return(ConfigJsonHandler.IsCorrectFormedUriStructure(_configJsonHandler.GetUrisConfig())); }
public static void Get() { UriStructureGeneral structureGeneral = new UriStructureGeneral() { Base = "http://graph.um.es" }; List <Characters> characters = new List <Characters>(); Characters charac = new Characters() { Character = "resource", LabelCharacter = "res" }; characters.Add(charac); structureGeneral.Characters = characters; Component baseC = new Component() { UriComponent = "base", UriComponentValue = "base", UriComponentOrder = 1, Mandatory = true, FinalCharacter = "/" }; Component character = new Component() { UriComponent = "character", UriComponentValue = "character@resource", UriComponentOrder = 2, Mandatory = true, FinalCharacter = "/" }; Component resource = new Component() { UriComponent = "resourceClass", UriComponentValue = "resourceClass", UriComponentOrder = 3, Mandatory = true, FinalCharacter = "/" }; Component identifier = new Component() { UriComponent = "identifier", UriComponentValue = "@ID", UriComponentOrder = 4, Mandatory = true, FinalCharacter = "" }; List <Component> componentes = new List <Component>(); componentes.Add(baseC); componentes.Add(character); componentes.Add(resource); componentes.Add(identifier); UriStructure uriStructure = new UriStructure() { Name = "test", Components = componentes }; structureGeneral.UriStructures = new List <UriStructure>(); structureGeneral.UriStructures.Add(uriStructure); ResourcesClass clas = new ResourcesClass() { LabelResourceClass = "project-object", ResourceClass = "Project", ResourceURI = "test" }; ResourcesClass clas2 = new ResourcesClass() { LabelResourceClass = "researcher", ResourceClass = "Researcher", ResourceURI = "test" }; structureGeneral.ResourcesClasses = new List <ResourcesClass>(); structureGeneral.ResourcesClasses.Add(clas); structureGeneral.ResourcesClasses.Add(clas2); string uriSchemaJson = JsonConvert.SerializeObject(structureGeneral); ConfigJsonHandler config = new ConfigJsonHandler(uriSchemaJson); Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); UriFormer uriFormer = new UriFormer(config.GetUrisConfig()); string uri = uriFormer.GetURI("Project", queryString); Console.WriteLine(uri); }