Ejemplo n.º 1
0
        protected override void InternalHasValidationResult(EntityValidationFacade validationFacade, KeyValuePair <string, List <dynamic> > property)
        {
            if (property.Value is null)
            {
                return;
            }

            var    metadataProperty = validationFacade.MetadataProperties.FirstOrDefault(t => t.Properties.GetValueOrNull(Graph.Metadata.Constants.EnterpriseCore.PidUri, true) == property.Key);
            string range            = metadataProperty?.Properties.GetValueOrNull(Graph.Metadata.Constants.Shacl.Range, true);

            // Value can be the identifier of the entity or the label of a new entity to be created
            validationFacade.RequestResource.Properties[property.Key] = property.Value.Select(value =>
            {
                if (!Regex.IsMatch(value, Common.Constants.Regex.ResourceKey))
                {
                    var labelUri = new Uri(Graph.Metadata.Constants.RDFS.Label);
                    if (!_entityService.CheckIfPropertyValueExists(labelUri, value, range, out string entityId))
                    {
                        var entityRequest = new BaseEntityRequestDTO();
                        entityRequest.Properties.Add(Graph.Metadata.Constants.RDF.Type, new List <dynamic>()
                        {
                            range
                        });
                        entityRequest.Properties.Add(Graph.Metadata.Constants.RDFS.Label, new List <dynamic>()
                        {
                            value
                        });

                        var createdEntity = _entityService.CreateEntity(entityRequest).Result;

                        return(createdEntity.Entity.Id);
                    }

                    return(entityId);
                }

                return(value);
            }).ToList();
        }
Ejemplo n.º 2
0
        public async Task <ResourceWriteResultCTO> CreateDistributionEndpoint(Uri resourcePidUri, bool createAsMainDistributionEndpoint, BaseEntityRequestDTO requestDistributionEndpoint)
        {
            var newEndpoint = _mapper.Map <Entity>(requestDistributionEndpoint);

            var resource = _resourceService.GetByPidUri(resourcePidUri);

            var endpoints = new List <dynamic>();

            if (resource.Properties.TryGetValue(Graph.Metadata.Constants.Resource.Distribution, out var repoEndpoints))
            {
                endpoints = repoEndpoints;
            }

            var mainEndpoints = new List <dynamic>();

            if (createAsMainDistributionEndpoint)
            {
                if (resource.Properties.TryGetValue(Graph.Metadata.Constants.Resource.MainDistribution, out var repoMainEndpoints))
                {
                    mainEndpoints = repoMainEndpoints;
                }

                resource.Properties.AddOrUpdate(Graph.Metadata.Constants.Resource.MainDistribution, new List <dynamic> {
                    newEndpoint
                });
            }
            else
            {
                endpoints.Add(newEndpoint);
            }

            endpoints.AddRange(mainEndpoints);

            resource.Properties.AddOrUpdate(Graph.Metadata.Constants.Resource.Distribution, endpoints);

            var requestResource = _mapper.Map <ResourceRequestDTO>(resource);

            return(await _resourceService.EditResource(resourcePidUri, requestResource).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        public async Task <ResourceWriteResultCTO> EditDistributionEndpoint(Uri distributionEndpointPidUri, bool editAsMainDistributionEndpoint, BaseEntityRequestDTO requestDistributionEndpoint)
        {
            var resourcePidUri = _resourceService.GetPidUriByDistributionEndpointPidUri(distributionEndpointPidUri);

            var resource = _resourceService.GetByPidUri(resourcePidUri);

            var newEndpoint = _mapper.Map <Entity>(requestDistributionEndpoint);

            var mainEndpoints = new List <dynamic>();

            if (resource.Properties.TryGetValue(Graph.Metadata.Constants.Resource.MainDistribution, out var mainRepoEndpoints))
            {
                mainEndpoints = FilterEndpoints(mainRepoEndpoints, distributionEndpointPidUri.ToString());
            }

            var endpoints = new List <dynamic>();

            if (resource.Properties.TryGetValue(Graph.Metadata.Constants.Resource.Distribution, out var repoEndpoints))
            {
                endpoints = FilterEndpoints(repoEndpoints, distributionEndpointPidUri.ToString());
            }

            if (editAsMainDistributionEndpoint)
            {
                endpoints.AddRange(mainEndpoints);
                mainEndpoints = new List <dynamic>()
                {
                    newEndpoint
                };
            }
            else
            {
                endpoints.Add(newEndpoint);
            }

            resource.Properties.AddOrUpdate(Graph.Metadata.Constants.Resource.MainDistribution, mainEndpoints);
            resource.Properties.AddOrUpdate(Graph.Metadata.Constants.Resource.Distribution, endpoints);

            var requestResource = _mapper.Map <ResourceRequestDTO>(resource);

            return(await _resourceService.EditResource(resource.PidUri, requestResource).ConfigureAwait(false));
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> Put([FromQuery] Uri distributionEndpointPidUri, [FromBody] BaseEntityRequestDTO requestDistributionEndpoint, [FromQuery] bool editAsMainDistributionEndpoint = false)
 {
     return(Ok(await _distributionEndpointService.EditDistributionEndpoint(distributionEndpointPidUri, editAsMainDistributionEndpoint, requestDistributionEndpoint).ConfigureAwait(false)));
 }
Ejemplo n.º 5
0
 public async Task <IActionResult> PostV3([FromQuery] Uri colidEntryPidUri, [FromBody] BaseEntityRequestDTO entity, [FromQuery] bool createAsMainDistributionEndpoint = false)
 {
     return(Ok(await _distributionEndpointService.CreateDistributionEndpoint(colidEntryPidUri, createAsMainDistributionEndpoint, entity).ConfigureAwait(false)));
 }