public void DeleteOrDeprecatePidUriTemplate(string id)
        {
            var pidUriTemplateGraph        = GetInstanceGraph();
            var historicInstanceGraph      = _metadataService.GetHistoricInstanceGraph();
            var resourceInstanceGraph      = _metadataService.GetInstanceGraph(PIDO.PidConcept);
            var resourceDraftInstanceGraph = _metadataService.GetInstanceGraph("draft");

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new MissingParameterException(Common.Constants.Messages.Request.MissingParameter, new List <string>()
                {
                    nameof(id)
                });
            }

            CheckIfEntityExists(id);

            var consumerGroupGraph = _metadataService.GetInstanceGraph(ConsumerGroup.Type);
            var consumerGroupReferenceForPidUriTemplate = _repository.CheckPidUriTemplateHasConsumerGroupReference(id, pidUriTemplateGraph, consumerGroupGraph, out var referenceId);

            // Throw error of reference exists
            if (consumerGroupReferenceForPidUriTemplate)
            {
                throw new ReferenceException(Common.Constants.Messages.PidUriTemplate.DeleteUnsuccessfulConsumerGroupReference, referenceId);
            }

            var colidEntryReferenceForPidURiTemplate = _repository.CheckPidUriTemplateHasColidEntryReference(id, pidUriTemplateGraph, resourceInstanceGraph, resourceDraftInstanceGraph, historicInstanceGraph);

            if (!colidEntryReferenceForPidURiTemplate)
            {
                _repository.DeleteEntity(id, pidUriTemplateGraph);

                _auditTrailLogService.AuditTrail($"PID URI template with id {id} deleted.");
                _cacheService.DeleteRelatedCacheEntries <PidUriTemplateService, PidUriTemplate>(id);
                return;
            }

            var pidUriTemplateResult = GetEntity(id);

            if (CheckTemplateHasStatus(pidUriTemplateResult, COLID.Graph.Metadata.Constants.PidUriTemplate.LifecycleStatus.Deprecated))
            {
                throw new BusinessException(Common.Constants.Messages.PidUriTemplate.DeleteUnsuccessfulAlreadyDeprecated);
            }

            pidUriTemplateResult.Properties.AddOrUpdate(COLID.Graph.Metadata.Constants.PidUriTemplate.HasLifecycleStatus, new List <dynamic> {
                COLID.Graph.Metadata.Constants.PidUriTemplate.LifecycleStatus.Deprecated
            });

            var pidUriTemplate     = _mapper.Map <PidUriTemplate>(pidUriTemplateResult);
            var metadataProperties = _metadataService.GetMetadataForEntityType(Type);

            _repository.UpdateEntity(pidUriTemplate, metadataProperties, pidUriTemplateGraph);
            _cacheService.DeleteRelatedCacheEntries <PidUriTemplateService, PidUriTemplate>(id);

            _auditTrailLogService.AuditTrail($"PID URI template with id {id} set as deprecated.");
        }
예제 #2
0
        private bool DeleteMarkedForDeletionResource(Resource resource, out string message)
        {
            // Append the property isDeleted to the parent resource and update it
            // TODO CK: shouldnt the response (true/false) be checked here?
            _resourceLinkingService.UnlinkResourceFromList(resource.PidUri, true, out message);

            // Since we need the inbound edges before deleting the entry, all inbound edges must be fetched at this point and passed on for indexing after deletion.
            var inboundProperties = _resourceRepository.GetAllInboundLinkedResourcePidUris(resource.PidUri);

            string entityType = resource.Properties.GetValueOrNull(Graph.Metadata.Constants.RDF.Type, true).ToString();
            var    metadata   = _metadataService.GetMetadataForEntityType(entityType);

            using (var transaction = _resourceRepository.CreateTransaction())
            {
                // Frist delete the history and all in- and outbound edges, then delete the resource marked for deletion itself
                _historyResourceService.DeleteHistoricResourceChain(resource.PidUri);
                _resourceRepository.DeleteMarkedForDeletion(resource.PidUri);
                transaction.Commit();

                _indexingService.SendResourceDeleted(resource, inboundProperties, metadata);

                _remoteAppDataService.NotifyResourceDeleted(resource);

                var auditMessage = $"Resource with piduri {resource.PidUri} deleted.";
                _auditTrailLogService.AuditTrail(auditMessage);
            }

            message = Common.Constants.Messages.Resource.Delete.DeleteSuccessfulResourcePublished;
            return(true);
        }
        public void DeleteOrDeprecateConsumerGroup(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new MissingParameterException(Common.Constants.Messages.Request.MissingParameter, new List <string>()
                {
                    nameof(id)
                });
            }

            var consumerGroupResult    = GetEntity(id);
            var consumerGroupReference = _repository.CheckConsumerGroupHasColidEntryReference(id);

            if (!consumerGroupReference)
            {
                _repository.DeleteEntity(id);
                _remoteAppDataService.DeleteConsumerGroup(new Uri(id));

                _auditTrailLogService.AuditTrail($"Consumer Group with id {id} deleted.");
                _cacheService.DeleteRelatedCacheEntries <ConsumerGroupService, ConsumerGroup>();
                return;
            }

            if (CheckConsumerGroupHasStatus(consumerGroupResult, Graph.Metadata.Constants.ConsumerGroup.LifecycleStatus.Deprecated))
            {
                throw new BusinessException(Common.Constants.Messages.ConsumerGroup.DeleteUnsuccessfulAlreadyDeprecated);
            }

            consumerGroupResult.Properties.AddOrUpdate(Graph.Metadata.Constants.ConsumerGroup.HasLifecycleStatus, new List <dynamic> {
                Graph.Metadata.Constants.ConsumerGroup.LifecycleStatus.Deprecated
            });

            var consumerGroup      = _mapper.Map <ConsumerGroup>(consumerGroupResult);
            var metadataProperties = _metadataService.GetMetadataForEntityType(Type);

            _repository.UpdateEntity(consumerGroup, metadataProperties);
            _cacheService.DeleteRelatedCacheEntries <ConsumerGroupService, ConsumerGroup>();
            _auditTrailLogService.AuditTrail($"Consumer Group with id {id} set as deprecated.");
        }
        public void DeleteGraph(Uri graph)
        {
            if (graph == null || !graph.IsAbsoluteUri)
            {
                throw new ArgumentException(Common.Constants.Messages.Graph.InvalidFormat, nameof(graph));
            }

            var graphs      = GetGraphs();
            var graphExists = graphs.TryGetFirstOrDefault(g => g.Name == graph, out var graphDto);

            if (!graphExists)
            {
                throw new GraphNotFoundException(Common.Constants.Messages.Graph.NotExists, graph);
            }

            if (graphDto.Status != Common.Enums.Graph.GraphStatus.Unreferenced)
            {
                throw new ReferenceException(Common.Constants.Messages.Graph.Referenced, graph.OriginalString);
            }

            _graphManagementRepo.DeleteGraph(graph);
            _auditTrailLogService.AuditTrail($"Graph in database with uri \"{graph}\" deleted.");
        }