// TODO: Cache public PidUriTemplateFlattened GetFlatPidUriTemplateByPidUriTemplate(Entity pidUriTemplate) { var result = new PidUriTemplateFlattened { Id = pidUriTemplate.Id }; string idTypeProp = pidUriTemplate.Properties.GetValueOrNull(Common.Constants.PidUriTemplate.HasPidUriTemplateIdType, true); if (!string.IsNullOrWhiteSpace(idTypeProp)) { result.IdType = _metadataService.GetPrefLabelForEntity(idTypeProp); } string suffixProp = pidUriTemplate.Properties.GetValueOrNull(Common.Constants.PidUriTemplate.HasPidUriTemplateSuffix, true); if (!string.IsNullOrWhiteSpace(suffixProp)) { result.Suffix = _metadataService.GetPrefLabelForEntity(suffixProp); } result.BaseUrl = pidUriTemplate.Properties.GetValueOrNull(Common.Constants.PidUriTemplate.HasBaseUrl, true) ?? string.Empty; result.Route = pidUriTemplate.Properties.GetValueOrNull(Common.Constants.PidUriTemplate.HasRoute, true) ?? string.Empty; int.TryParse(pidUriTemplate.Properties.GetValueOrNull(Common.Constants.PidUriTemplate.HasIdLength, true) ?? "0", out int idLength); result.IdLength = idLength; return(result); }
public async Task <ValidationResult> ValidateEntity(Entity entity, IList <MetadataProperty> metadataProperties) { var resourceGraph = GetResourceGraph(entity, metadataProperties); var shapesGraph = GetShapesGraph(); var processor = new ShapesGraph(shapesGraph); var report = processor.Validate(resourceGraph); var validationResult = CreateValidationResult(report); return(await Task.FromResult(validationResult)); }
/// <summary> /// has side effects! updates triplestore /// </summary> /// <param name="entity"></param> /// <param name="metadataProperties"></param> /// <returns></returns> public async Task <ValidationResult> ValidateEntity(Entity entity, IList <MetadataProperty> metadataProperties) { var resourceGraph = GetResourceGraph(entity, metadataProperties); var shapesGraph = GetShapesGraph(); var processor = new ShapesGraph(shapesGraph); var report = processor.Validate(resourceGraph); var validationResult = CreateValidationResult(report); NTriplesWriter rdfNTriplesWriter = new NTriplesWriter(); validationResult.Triples = VDS.RDF.Writing.StringWriter.Write(resourceGraph, rdfNTriplesWriter); return(await Task.FromResult(validationResult)); }
/// <summary> /// Converts the entity into an rdf graph /// </summary> /// <param name="entity">Entity to be converted</param> /// <param name="metadataProperties">Metadata of the entity to be converted</param> /// <returns>RDf graph of entity</returns> private IGraph GetResourceGraph(Entity entity, IList <MetadataProperty> metadataProperties) { var store = new TripleStore(); //Create InsertString from resource if (metadataProperties.IsNullOrEmpty()) { string entityType = entity.Properties.GetValueOrNull(Graph.Metadata.Constants.RDF.Type, true).ToString(); metadataProperties = _metadataService.GetMetadataForEntityType(entityType); } var resourceInsertString = _entityRepository.GenerateInsertQuery(entity, metadataProperties, string.Empty, null); store.ExecuteUpdate(resourceInsertString.ToString()); return(store.Graphs.FirstOrDefault()); }
private void RemoveEndpointFromProperties(Entity resource, Uri distributionEndpointPidUri) { // Remove distribution endpoint from pid entry if (resource.Properties.TryGetValue(Graph.Metadata.Constants.Resource.Distribution, out List <dynamic> endpoints)) { int indexToRemove = 0; bool indexSet = false; var index = 0; foreach (var endpoint in endpoints) { if (DynamicExtension.IsType <Entity>(endpoint, out Entity distributionEndpoint)) { if (distributionEndpoint.Properties.TryGetValue(EnterpriseCore.PidUri, out List <dynamic> pidUriValue)) { Entity pidUriEntity = pidUriValue.FirstOrDefault(); if (pidUriEntity.Id == distributionEndpointPidUri.ToString()) { indexToRemove = index; indexSet = true; break; } } } index++; } if (indexSet) { endpoints.RemoveAt(indexToRemove); if (!endpoints.Any()) { resource.Properties.Remove(Graph.Metadata.Constants.Resource.Distribution); } else { resource.Properties[Graph.Metadata.Constants.Resource.Distribution] = endpoints; } } } }