Пример #1
0
        private async Task <(IList <SmintIoAsset>, string, bool)> LoadAssetsAsync(string continuationUuid, bool compoundAssetsSupported, bool binaryUpdatesSupported)
        {
            await SetupClapicOpenApiClientAsync();

            var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync();

            IList <SmintIoAsset> assets = new List <SmintIoAsset>();

            SyncLicensePurchaseTransactionQueryResult syncLptQueryResult = await _retryPolicy.ExecuteAsync(async() =>
            {
                // get a new access token in case it was refreshed
                var tokenDatabaseModel           = await _smintIoTokenDatabaseProvider.GetTokenDatabaseModelAsync();
                _clapicOpenApiClient.AccessToken = tokenDatabaseModel.AccessToken;
                return(await _clapicOpenApiClient.GetLicensePurchaseTransactionsForSyncAsync(
                           continuationUuid: continuationUuid,
                           limit: 10));
            });

            if (syncLptQueryResult.Count == 0)
            {
                return(assets, syncLptQueryResult.Continuation_uuid, false);
            }

            bool hasAssets = false;

            foreach (var lpt in syncLptQueryResult.License_purchase_transactions)
            {
                bool?isEditorialUse = null;

                foreach (var license_term in lpt.License_terms)
                {
                    // make sure we do not store editorial use information if no information is there!

                    if (license_term.Is_editorial_use != null)
                    {
                        if (license_term.Is_editorial_use == true)
                        {
                            // if we have a restrictions, always indicate

                            isEditorialUse = true;
                        }
                        else if (license_term.Is_editorial_use == false)
                        {
                            // if we have no restriction, only store, if we have no other restriction

                            if (isEditorialUse == null)
                            {
                                isEditorialUse = false;
                            }
                        }
                    }
                }

                string url = $"https://{smintIoSettingsDatabaseModel.TenantId}.smint.io/project/{lpt.Project_uuid}/content-element/{lpt.Content_element.Uuid}";

                var importLanguages = smintIoSettingsDatabaseModel.ImportLanguages;

                var asset = new SmintIoAsset()
                {
                    ContentElementUuid                   = lpt.Content_element.Uuid,
                    LicensePurchaseTransactionUuid       = lpt.Uuid,
                    ReusedLicensePurchaseTransactionUuid = lpt.Reused_license_purchase_transaction_uuid,
                    CartPurchaseTransactionUuid          = lpt.Cart_purchase_transaction_uuid,
                    State                         = lpt.State,
                    Provider                      = lpt.Content_element.Provider,
                    ContentType                   = lpt.Content_element.Content_type,
                    Name                          = GetValuesForImportLanguages(importLanguages, lpt.Content_element.Name),
                    Description                   = GetValuesForImportLanguages(importLanguages, lpt.Content_element.Description),
                    Keywords                      = GetGroupedValuesForImportLanguages(importLanguages, lpt.Content_element.Keywords),
                    Category                      = lpt.Content_element.Content_category,
                    ReleaseDetails                = GetReleaseDetails(importLanguages, lpt),
                    CopyrightNotices              = GetValuesForImportLanguages(importLanguages, lpt.Content_element.Copyright_notices),
                    ProjectUuid                   = lpt.Project_uuid,
                    ProjectName                   = GetValuesForImportLanguages(importLanguages, lpt.Project_name),
                    CollectionUuid                = lpt.Collection_uuid,
                    CollectionName                = GetValuesForImportLanguages(importLanguages, lpt.Collection_name),
                    LicenseeUuid                  = lpt.Licensee_uuid,
                    LicenseeName                  = lpt.Licensee_name,
                    LicenseType                   = lpt.Offering.License_type,
                    LicenseText                   = GetValuesForImportLanguages(importLanguages, lpt.License_text.Effective_text),
                    LicenseUrls                   = GetGroupedUrlValuesForImportLanguages(importLanguages, lpt.Offering.License_urls),
                    LicenseTerms                  = GetLicenseTerms(importLanguages, lpt),
                    DownloadConstraints           = GetDownloadConstraints(lpt),
                    IsEditorialUse                = isEditorialUse,
                    HasRestrictiveLicenseTerms    = lpt.Has_potentially_restrictive_license_terms ?? false,
                    SmintIoUrl                    = url,
                    PurchasedAt                   = lpt.Purchased_at,
                    CreatedAt                     = (DateTimeOffset)lpt.Created_at,
                    LastUpdatedAt                 = lpt.Last_updated_at ?? lpt.Created_at ?? DateTimeOffset.Now,
                    RawLicensePurchaseTransaction = lpt
                };

                // we need to store this separately because list will be empty if all assets of the batch have Can_be_synced == false

                hasAssets = true;

                if (lpt.Can_be_synced ?? false)
                {
                    var syncBinaries =
                        await _clapicOpenApiClient.GetLicensePurchaseTransactionBinariesForSyncAsync(asset.CartPurchaseTransactionUuid, asset.LicensePurchaseTransactionUuid);

                    asset.Binaries = GetBinaries(importLanguages, syncBinaries, compoundAssetsSupported, binaryUpdatesSupported);

                    assets.Add(asset);
                }
            }

            return(assets, syncLptQueryResult.Continuation_uuid, hasAssets);
        }
Пример #2
0
        private void SetContentMetadata(TSyncAsset targetAsset, SmintIoAsset rawAsset, SmintIoBinary binary)
        {
            var contentTypeString = !string.IsNullOrEmpty(binary?.ContentType) ? binary.ContentType : rawAsset.ContentType;

            targetAsset.SetContentElementUuid(rawAsset.ContentElementUuid);
            targetAsset.SetContentProvider(GetContentProviderKey(rawAsset.Provider));
            targetAsset.SetContentType(GetContentTypeKey(contentTypeString));
            targetAsset.SetContentCategory(GetContentCategoryKey(rawAsset.Category));
            targetAsset.SetSmintIoUrl(rawAsset.SmintIoUrl);
            targetAsset.SetPurchasedAt(rawAsset.PurchasedAt);
            targetAsset.SetCreatedAt(rawAsset.CreatedAt);
            targetAsset.SetCartUuid(rawAsset.CartPurchaseTransactionUuid);
            targetAsset.SetHasBeenCancelled(rawAsset.State == Client.Generated.LicensePurchaseTransactionStateEnum.Cancelled);

            if (!string.IsNullOrEmpty(binary?.BinaryType))
            {
                targetAsset.SetBinaryType(GetBinaryTypeKey(binary.BinaryType));
            }

            if (rawAsset.LastUpdatedAt != null)
            {
                targetAsset.SetLastUpdatedAt((DateTimeOffset)rawAsset.LastUpdatedAt);
            }

            if (binary?.Name?.Count > 0)
            {
                targetAsset.SetNameInternal(binary.Name);
            }
            else if (rawAsset.Name?.Count > 0)
            {
                targetAsset.SetNameInternal(rawAsset.Name);
            }

            if (binary?.Description?.Count > 0)
            {
                targetAsset.SetDescription(binary.Description);
            }
            else if (rawAsset.Description?.Count > 0)
            {
                targetAsset.SetDescription(rawAsset.Description);
            }

            if (!string.IsNullOrEmpty(rawAsset.ProjectUuid))
            {
                targetAsset.SetProjectUuid(rawAsset.ProjectUuid);
            }

            if (rawAsset.ProjectName?.Count > 0)
            {
                targetAsset.SetProjectName(rawAsset.ProjectName);
            }

            if (!string.IsNullOrEmpty(rawAsset.CollectionUuid))
            {
                targetAsset.SetCollectionUuid(rawAsset.CollectionUuid);
            }

            if (rawAsset.CollectionName?.Count > 0)
            {
                targetAsset.SetCollectionName(rawAsset.CollectionName);
            }

            if (rawAsset.Keywords?.Count > 0)
            {
                targetAsset.SetKeywords(rawAsset.Keywords);
            }

            if (rawAsset.CopyrightNotices?.Count > 0)
            {
                targetAsset.SetCopyrightNotices(rawAsset.CopyrightNotices);
            }

            if (binary != null)
            {
                targetAsset.SetBinaryUuidInternal(binary.Uuid);

                if (binary.Usage?.Count > 0)
                {
                    targetAsset.SetBinaryUsageInternal(binary.Usage);
                }

                var binaryCulture = binary.Culture;
                if (!string.IsNullOrEmpty(binaryCulture))
                {
                    targetAsset.SetBinaryCulture(binaryCulture);
                }

                targetAsset.SetBinaryVersionInternal(binary.Version);
            }
        }
Пример #3
0
        private void SetLicenseMetadata(TSyncAsset targetAsset, SmintIoAsset rawAsset)
        {
            targetAsset.SetLicenseType(GetLicenseTypeKey(rawAsset.LicenseType));

            targetAsset.SetLicenseeUuid(rawAsset.LicenseeUuid);
            targetAsset.SetLicenseeName(rawAsset.LicenseeName);

            if (rawAsset.LicenseText?.Count > 0)
            {
                targetAsset.SetLicenseText(rawAsset.LicenseText);
            }

            if (rawAsset.LicenseUrls?.Count > 0)
            {
                targetAsset.SetLicenseUrls(rawAsset.LicenseUrls);
            }

            if (rawAsset.LicenseTerms?.Count > 0)
            {
                targetAsset.SetLicenseTerms(GetLicenseTerms(rawAsset.LicenseTerms));
            }

            if (rawAsset.DownloadConstraints != null)
            {
                var rawDownloadConstraints = rawAsset.DownloadConstraints;

                var targetDownloadConstraints = _syncTargetDataFactory.CreateSyncDownloadConstraints();

                if (rawDownloadConstraints.MaxDownloads != null)
                {
                    targetDownloadConstraints.SetMaxDownloads((int)rawDownloadConstraints.MaxDownloads);
                }

                if (rawDownloadConstraints.MaxUsers != null)
                {
                    targetDownloadConstraints.SetMaxUsers((int)rawDownloadConstraints.MaxUsers);
                }

                if (rawDownloadConstraints.MaxReuses != null)
                {
                    targetDownloadConstraints.SetMaxReuses((int)rawDownloadConstraints.MaxReuses);
                }

                targetAsset.SetDownloadConstraints(targetDownloadConstraints);
            }

            if (rawAsset.ReleaseDetails != null)
            {
                var rawReleaseDetails = rawAsset.ReleaseDetails;

                var targetReleaseDetails = _syncTargetDataFactory.CreateSyncReleaseDetails();

                string modelReleaseState = null;
                if (!string.IsNullOrEmpty(rawReleaseDetails.ModelReleaseState))
                {
                    modelReleaseState = GetReleaseStateKey(rawReleaseDetails.ModelReleaseState);
                }

                string propertyReleaseState = null;
                if (!string.IsNullOrEmpty(rawReleaseDetails.PropertyReleaseState))
                {
                    propertyReleaseState = GetReleaseStateKey(rawReleaseDetails.PropertyReleaseState);
                }

                if (!string.IsNullOrEmpty(modelReleaseState))
                {
                    targetReleaseDetails.SetModelReleaseState(modelReleaseState);
                }

                if (!string.IsNullOrEmpty(propertyReleaseState))
                {
                    targetReleaseDetails.SetPropertyReleaseState(propertyReleaseState);
                }

                if (rawReleaseDetails.ProviderAllowedUseComment?.Count > 0)
                {
                    targetReleaseDetails.SetProviderAllowedUseComment(rawReleaseDetails.ProviderAllowedUseComment);
                }

                if (rawReleaseDetails.ProviderReleaseComment?.Count > 0)
                {
                    targetReleaseDetails.SetProviderReleaseComment(rawReleaseDetails.ProviderReleaseComment);
                }

                if (rawReleaseDetails.ProviderUsageConstraints?.Count > 0)
                {
                    targetReleaseDetails.SetProviderUsageConstraints(rawReleaseDetails.ProviderUsageConstraints);
                }

                targetAsset.SetReleaseDetails(targetReleaseDetails);
            }

            if (rawAsset.IsEditorialUse != null)
            {
                targetAsset.SetIsEditorialUse((bool)rawAsset.IsEditorialUse);
            }

            if (rawAsset.HasRestrictiveLicenseTerms != null)
            {
                targetAsset.SetHasRestrictiveLicenseTerms((bool)rawAsset.HasRestrictiveLicenseTerms);
            }
        }
Пример #4
0
 internal void SetAsset(SmintIoAsset asset)
 {
     Asset = asset;
 }