public async Task <LicenseStorageItem> CreateLicense(IOtherLicenseDetails nomination) { var licenseId = Guid.NewGuid(); RequestOptions dbOptions = new RequestOptions { PartitionKey = new PartitionKey(LicenseStorageItem.LicenseDatasetId.ToString()) }; var licenseStorageItem = new LicenseStorageItem { Id = licenseId, IsStandard = false, Name = nomination.OtherLicenseName }; if (nomination.NominationLicenseType == NominationLicenseType.InputFile) { licenseStorageItem.FileName = nomination.OtherLicenseFileName; licenseStorageItem.FileContentType = nomination.OtherLicenseFileContentType; licenseStorageItem.IsFileBased = true; licenseStorageItem.FileContent = nomination.OtherLicenseFileContent; } var documentCollection = this.DatasetDocumentCollectionUri; // Create document record ResourceResponse <Microsoft.Azure.Documents.Document> licenseRecord = await Client.UpsertDocumentAsync( documentCollection, licenseStorageItem, dbOptions); if (nomination.NominationLicenseType == NominationLicenseType.HtmlText) { await CreateHtmlContentLicenseContentAttachment(nomination, licenseRecord); } if (!string.IsNullOrEmpty(nomination.OtherLicenseAdditionalInfoUrl)) { var licenseRecordLink = new Attachment { Id = "Source", // "Slug" is ID with hard-attach ContentType = "text/plain", MediaLink = nomination.OtherLicenseAdditionalInfoUrl }; var licenseRefAttachment = await Client.UpsertAttachmentAsync(licenseRecord.Resource.SelfLink, licenseRecordLink, dbOptions); } return(licenseStorageItem); }
public License(LicenseStorageItem source) { Id = source.Id; Name = source.Name; IsStandard = source.IsStandard; ContentUri = source.IsFileBased ? new Uri($"/licenses/{source.Id}/file", UriKind.Relative) : new Uri($"/licenses/{source.Id}/content", UriKind.Relative); FileName = source.FileName; FileContentType = source.FileContentType; IsFileBased = source.IsFileBased; FileContent = source.FileContent; }
public static DatasetNominationStorageItem DatasetToNomination(DatasetStorageItem dataset, ContactInfoOptions contactOptions, LicenseStorageItem license) { return(new DatasetNominationStorageItem { Id = dataset.Id, DatasetId = WellKnownIds.DatasetNominationDatasetId, Name = dataset.Name, Description = dataset.Description, Domain = dataset.Domain, DomainId = dataset.DomainId, ProjectUri = dataset.ProjectUri ?? dataset.SourceUri, SourceUri = dataset.SourceUri ?? dataset.ProjectUri, Version = dataset.Version, Published = dataset.Published, Created = dataset.Created, Modified = dataset.Modified, License = license?.Name ?? dataset.License, LicenseId = license?.Id ?? dataset.LicenseId, Tags = (dataset.Tags ?? Enumerable.Empty <string>()).ToList(), DigitalObjectIdentifier = dataset.DigitalObjectIdentifier, ContactName = contactOptions.Name, ContactInfo = contactOptions.Email, UserId = Guid.Empty, CreatedByUserName = dataset.CreatedByUserName, CreatedByUserEmail = dataset.CreatedByUserEmail, ModifiedByUserName = dataset.ModifiedByUserName, ModifiedByUserEmail = dataset.ModifiedByUserEmail, IsDownloadAllowed = dataset?.IsDownloadAllowed ?? false, NominationStatus = NominationStatus.PendingApproval, }); }