Beispiel #1
0
        public string DeleteResource(Uri pidUri)
        {
            CheckIfResourceExist(pidUri);

            using (var lockService = _lockServiceFactory.CreateLockService())
            {
                lockService.CreateLock(pidUri.ToString());

                var    resource = GetByPidUri(pidUri);
                string resourceLifeCycleStatus =
                    resource?.Properties.GetValueOrNull(Graph.Metadata.Constants.Resource.HasEntryLifecycleStatus, true);
                string deleteMessage = string.Empty;
                switch (resourceLifeCycleStatus)
                {
                case Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.Draft
                    when !string.IsNullOrWhiteSpace(resource.PublishedVersion):
                {
                    // TODO: Remove later after testing - No need to delete it, because the edge is already removed in DeleteDraftResource
                    //_resourceRepository.DeleteProperty(new Uri(resource.PublishedVersion),
                    //    new Uri(Constants.Metadata.HasPidEntryDraft), new Uri(resource.Id));

                    DeleteDraftResource(resource, out deleteMessage);
                    return(deleteMessage);
                }

                case Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.Draft
                    when string.IsNullOrWhiteSpace(resource.PublishedVersion):
                {
                    if (!_resourceLinkingService.UnlinkResourceFromList(pidUri, true,
                                                                        out string unlinkMessage))
                    {
                        return(unlinkMessage);
                    }

                    DeleteDraftResource(resource, out deleteMessage);
                    _remoteAppDataService.NotifyResourceDeleted(resource);

                    return(deleteMessage);
                }

                case Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.Published:
                    throw new BusinessException(Common.Constants.Messages.Resource.Delete.DeleteFailedNotMarkedDeleted);

                case Graph.Metadata.Constants.Resource.ColidEntryLifecycleStatus.MarkedForDeletion:
                    if (!_userInfoService.HasAdminPrivileges())
                    {
                        throw new BusinessException(Common.Constants.Messages.Resource.Delete.DeleteFailedNoAdminRights);
                    }

                    DeleteMarkedForDeletionResource(resource, out deleteMessage);
                    return(deleteMessage);

                default:
                    throw new BusinessException(Common.Constants.Messages.Resource.Delete.DeleteFailed);
                }
            }
        }