Exemplo n.º 1
0
        public ValidationResult IsDatasetEditValidForUpdate(DatasetEditStorageItem dataset)
        {
            var validator = new DatasetEditValidator();
            var result    = validator.Validate(dataset);

            return(result);
        }
Exemplo n.º 2
0
        private async Task UpdateDatsetDocFromEditDoc(DatasetEditStorageItem dataset, CancellationToken token)
        {
            // Create the license document (if applicable)
            if (dataset.NominationLicenseType == NominationLicenseType.HtmlText || dataset.NominationLicenseType == NominationLicenseType.InputFile)
            {
                var license = await DatasetStorage.CreateLicense(dataset);

                if (license != null)
                {
                    dataset.LicenseId = license.Id;
                    dataset.License   = license.Name;
                }
            }

            // Update the dataset record
            var docUri  = CreateDatasetDocumentUri(dataset.Id);
            var reqOpts = new RequestOptions
            {
                PartitionKey = new PartitionKey(dataset.Id.ToString())
            };
            var document = await Client.ReadDocumentAsync <DatasetStorageItem>(docUri, reqOpts);

            var current = document.Document;

            current.Name                    = dataset.Name;
            current.Description             = dataset.Description;
            current.Domain                  = dataset.Domain;
            current.DomainId                = dataset.DomainId;
            current.SourceUri               = dataset.SourceUri;
            current.ProjectUri              = dataset.ProjectUri;
            current.Version                 = dataset.Version;
            current.Published               = dataset.Published;
            current.License                 = dataset.License;
            current.LicenseId               = dataset.LicenseId.GetValueOrDefault();
            current.Tags                    = dataset.Tags;
            current.DigitalObjectIdentifier = dataset.DigitalObjectIdentifier;
            current.IsDownloadAllowed       = dataset.IsDownloadAllowed;
            await Client.ReplaceDocumentAsync(docUri, current, reqOpts);

            // Delete the original dataset edit record
            await Client.DeleteDocumentAsync(
                UserDataDocumentUriById(dataset.Id.ToString()),
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            },
                token);

            // Update Azure Search with the latest document
            await DatasetStorage.UpdateDatasetDetailsInSearchIndex(dataset.Id, token);
        }
Exemplo n.º 3
0
 public void Map(DatasetStorageItem source, DatasetEditStorageItem destination)
 {
     destination.Id                            = source.Id;
     destination.DatasetId                     = WellKnownIds.DatasetEditDatasetId;
     destination.Name                          = source.Name;
     destination.Description                   = source.Description;
     destination.Domain                        = source.Domain;
     destination.DomainId                      = source.DomainId;
     destination.SourceUri                     = source.SourceUri;
     destination.ProjectUri                    = source.ProjectUri;
     destination.Version                       = source.Version;
     destination.Published                     = source.Published;
     destination.Created                       = source.Created;
     destination.Modified                      = source.Modified;
     destination.License                       = source.License;
     destination.LicenseId                     = source.LicenseId;
     destination.Tags                          = source.Tags ?? new List <string>();
     destination.CreatedByUserName             = source.CreatedByUserName;
     destination.CreatedByUserEmail            = source.CreatedByUserEmail;
     destination.ModifiedByUserName            = source.ModifiedByUserName;
     destination.ModifiedByUserEmail           = source.ModifiedByUserEmail;
     destination.IsDownloadAllowed             = source.IsDownloadAllowed.GetValueOrDefault();
     destination.DigitalObjectIdentifier       = source.DigitalObjectIdentifier;
     destination.EditStatus                    = DatasetEditStatus.Unmodified;
     destination.NominationStatus              = NominationStatus.PendingApproval;
     destination.NominationLicenseType         = NominationLicenseType.Standard;
     destination.OtherLicenseAdditionalInfoUrl = null;
     destination.OtherLicenseContentHtml       = null;
     destination.OtherLicenseFileContent       = null;
     destination.OtherLicenseFileContentType   = null;
     destination.OtherLicenseName              = null;
     destination.OtherLicenseFileName          = null;
     if (source.DatasetOwners != null & source.DatasetOwners.Count > 0)
     {
         destination.ContactName = string.Join(";", source.DatasetOwners.Select(d => d.Name));
         destination.ContactInfo = string.Join(";", source.DatasetOwners.Select(d => d.Email));
     }
 }
Exemplo n.º 4
0
        public async Task <DatasetEditStorageItem> UpdateDataset(Guid id, IPrincipal user, DatasetEditStorageItem updated, CancellationToken token)
        {
            var(original, current) = await VerifyDatasetOwnership(id, user, token);

            if (original == null)
            {
                throw new InvalidOperationException("Invalid dataset id.");
            }

            if (current == null)
            {
                current            = original.ToDatasetEditStorageItem();
                current.EditStatus = DatasetEditStatus.DetailsModified;
            }

            current.Name                    = updated.Name;
            current.Description             = updated.Description;
            current.Domain                  = updated.Domain;
            current.DomainId                = updated.DomainId;
            current.SourceUri               = updated.SourceUri;
            current.ProjectUri              = updated.ProjectUri;
            current.Version                 = updated.Version;
            current.Published               = updated.Published;
            current.License                 = updated.License;
            current.LicenseId               = updated.LicenseId;
            current.Tags                    = updated.Tags;
            current.DigitalObjectIdentifier = updated.DigitalObjectIdentifier;
            current.IsDownloadAllowed       = updated.IsDownloadAllowed;

            current.NominationLicenseType = updated.NominationLicenseType;
            switch (updated.NominationLicenseType)
            {
            case NominationLicenseType.Unknown:
            case NominationLicenseType.Standard:
                current.OtherLicenseName = null;
                current.OtherLicenseAdditionalInfoUrl = null;
                current.OtherLicenseContentHtml       = null;
                current.OtherLicenseFileContent       = null;
                current.OtherLicenseFileContentType   = null;
                current.OtherLicenseFileName          = null;
                break;

            case NominationLicenseType.HtmlText:
                current.OtherLicenseName = updated.OtherLicenseName;
                current.OtherLicenseAdditionalInfoUrl = updated.OtherLicenseAdditionalInfoUrl;
                current.OtherLicenseContentHtml       = updated.OtherLicenseContentHtml;
                current.OtherLicenseFileContent       = null;
                current.OtherLicenseFileContentType   = null;
                current.OtherLicenseFileName          = null;
                break;

            case NominationLicenseType.InputFile:
                current.OtherLicenseName = updated.OtherLicenseName;
                current.OtherLicenseAdditionalInfoUrl = updated.OtherLicenseAdditionalInfoUrl;
                current.OtherLicenseContentHtml       = null;
                if (updated.OtherLicenseFileContent != null)
                {
                    current.OtherLicenseFileContent     = updated.OtherLicenseFileContent;
                    current.OtherLicenseFileContentType = updated.OtherLicenseFileContentType;
                    current.OtherLicenseFileName        = updated.OtherLicenseFileName;
                }
                break;
            }

            return(await UpdateDatasetEditItemDocument(user, current, token));
        }
Exemplo n.º 5
0
        private async Task <DatasetEditStorageItem> UpdateDatasetEditItemDocument(IPrincipal user, DatasetEditStorageItem updated, CancellationToken token)
        {
            updated.Modified            = DateTime.UtcNow;
            updated.ModifiedByUserName  = user.GetUserName();
            updated.ModifiedByUserEmail = user.GetUserEmail();

            var result = await Client.UpsertDocumentAsync(
                UserDataDocumentCollectionUri,
                updated,
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            },
                false,
                token);

            updated = (dynamic)result.Resource;
            return(updated);
        }
Exemplo n.º 6
0
        private async Task CreateNominationDocFromEditDoc(DatasetEditStorageItem dataset, CancellationToken token)
        {
            // Disallow changes to the edited container
            await SasTokens.DisableSasTokenForUpdatingDatasetContainer(dataset.ContentEditAccount, dataset.ContentEditContainer);

            // Update the status of edit document.
            dataset.EditStatus = DatasetEditStatus.Importing;
            await Client.ReplaceDocumentAsync(
                UserDataDocumentUriById(dataset.Id.ToString()),
                dataset,
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            },
                token);

            // Create nomination document
            var nomination = new DatasetNominationStorageItem
            {
                Id                            = dataset.Id,
                DatasetId                     = WellKnownIds.DatasetNominationDatasetId,
                Name                          = dataset.Name,
                Description                   = dataset.Description,
                Domain                        = dataset.Domain,
                DomainId                      = dataset.DomainId,
                SourceUri                     = dataset.SourceUri,
                ProjectUri                    = dataset.ProjectUri,
                Version                       = dataset.Version,
                Published                     = dataset.Published,
                Created                       = dataset.Created,
                Modified                      = dataset.Modified,
                License                       = dataset.License,
                LicenseId                     = dataset.LicenseId,
                Tags                          = (dataset.Tags ?? Enumerable.Empty <string>()).ToList(),
                ContactName                   = dataset.ContactName,
                ContactInfo                   = dataset.ContactInfo,
                CreatedByUserId               = dataset.CreatedByUserId,
                CreatedByUserName             = dataset.CreatedByUserName,
                CreatedByUserEmail            = dataset.CreatedByUserEmail,
                ModifiedByUserName            = dataset.ModifiedByUserName,
                ModifiedByUserEmail           = dataset.ModifiedByUserEmail,
                IsDownloadAllowed             = dataset.IsDownloadAllowed,
                NominationStatus              = NominationStatus.Importing,
                NominationLicenseType         = dataset.NominationLicenseType,
                DigitalObjectIdentifier       = dataset.DigitalObjectIdentifier,
                OtherLicenseContentHtml       = dataset.OtherLicenseContentHtml,
                OtherLicenseFileContent       = dataset.OtherLicenseFileContent,
                OtherLicenseFileContentType   = dataset.OtherLicenseFileContentType,
                OtherLicenseAdditionalInfoUrl = dataset.OtherLicenseAdditionalInfoUrl,
                OtherLicenseName              = dataset.OtherLicenseName,
                OtherLicenseFileName          = dataset.OtherLicenseFileName
            };
            await Client.UpsertDocumentAsync(
                UserDataDocumentCollectionUri,
                nomination,
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString())
            },
                false,
                token);

            // Point nomination document to updated container
            var datasetRecordLink = new Attachment
            {
                Id          = "Content",
                ContentType = "x-azure-blockstorage",
                MediaLink   = SasTokens.GetContainerMediaLink(
                    dataset.ContentEditAccount,
                    dataset.ContentEditContainer)
            };

            datasetRecordLink.SetPropertyValue("storageType", "blob");
            datasetRecordLink.SetPropertyValue("container", dataset.ContentEditContainer);
            datasetRecordLink.SetPropertyValue("account", dataset.ContentEditAccount);
            await Client.UpsertAttachmentAsync(
                UserDataDocumentUriById(dataset.Id.ToString()),
                datasetRecordLink,
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString())
            },
                token);
        }
Exemplo n.º 7
0
 public static DatasetEditViewModel ToDatasetEditViewModel(this DatasetEditStorageItem source, Action <DatasetEditViewModel> update = null)
 {
     return(ModelMapper <DatasetEditStorageItemMapper> .Mapper.Map(source).WithUpdate(update));
 }