Пример #1
0
        public async Task <IActionResult> EditResource(ResourceDTO resource)
        {
            var output = await _service.EditResource(resource);

            if (output.IsErrorOccured == true)
            {
                return(BadRequest(output));
            }
            else
            {
                return(Ok(output));
            }
        }
Пример #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));
        }
        public async void EditResource_Success()
        {
            // Arrange
            var requestBuilder = new ResourceBuilder()
                                 .GenerateSampleData();

            var request = requestBuilder.BuildRequestDto();

            var resource    = requestBuilder.Build();
            var publishedId = Graph.Metadata.Constants.Entity.IdPrefix + Guid.NewGuid();

            resource.Id = publishedId;

            var resourceCto = new ResourcesCTO(null, resource);

            _mockResourceRepo.Setup(s => s.GetResourcesByPidUri(resource.PidUri, It.IsAny <IList <string> >())).Returns(resourceCto);

            var validationFacade        = new EntityValidationFacade(ResourceCrudAction.Create, resource, resourceCto, request.HasPreviousVersion, _metadata, null);
            var validationResult        = new ValidationResult();
            var preProcessServiceResult = new Tuple <ValidationResult, bool, EntityValidationFacade>(validationResult, false, validationFacade);

            var newResourceId = string.Empty;

            _mockPreProcessService.Setup(t => t.ValidateAndPreProcessResource(It.IsAny <string>(), request, It.IsAny <ResourcesCTO>(), ResourceCrudAction.Update, It.IsAny <bool>(), It.IsAny <string>()))
            .ReturnsAsync(preProcessServiceResult)
            .Callback <string, ResourceRequestDTO, ResourcesCTO, ResourceCrudAction, bool, string>((a, b, c, d, e, f) =>
            {
                newResourceId = a;
                validationResult.Results.Add(new ValidationResultProperty(a, "some path", "some value", "some message", ValidationResultSeverity.Warning));
            });

            // Act
            var result = await _service.EditResource(resource.PidUri, request);

            // Assert
            Assert.All(result.ValidationResult.Results, t =>
            {
                Assert.Equal(t.Node, newResourceId);
            });

            _mockResourceRepo.Verify(s => s.DeleteDraft(result.Resource.PidUri, new Uri(result.Resource.Id)), Times.Once);
            _mockResourceRepo.Verify(s => s.Create(resource, _metadata), Times.Once);
            _mockResourceRepo.Verify(s => s.CreateLinkingProperty(resource.PidUri, new Uri(
                                                                      Graph.Metadata.Constants.Resource.HasPidEntryDraft),
                                                                  Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.Published,
                                                                  Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.Draft), Times.Once);
            _mockIdentifierService.Verify(s => s.DeleteAllUnpublishedIdentifiers(It.IsAny <Entity>()), Times.Never);
        }
        public async Task <IActionResult> EditResource([FromQuery] Uri pidUri, [FromBody] ResourceRequestDTO resource)
        {
            var result = await _resourceService.EditResource(pidUri, resource);

            return(Ok(result));
        }