< Summary

Class:DCLServices.WearablesCatalogService.WearablesCatalogServiceProxy
Assembly:WearablesCatalogService
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/WearablesCatalogServiceProxy.cs
Covered lines:26
Uncovered lines:49
Coverable lines:75
Total lines:193
Line coverage:34.6% (26 of 75)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:23
Method coverage:30.4% (7 of 23)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WearablesCatalogServiceProxy(...)0%110100%
Initialize()0%2.52050%
Dispose()0%2.52050%
GetThirdPartyCollectionsAsync()0%42600%
RequestOwnedWearablesAsync()0%42600%
RequestOwnedWearablesAsync()0%42600%
RequestBaseWearablesAsync()0%42600%
RequestThirdPartyWearablesByCollectionAsync()0%42600%
RequestWearableAsync()0%42600%
RequestWearableFromBuilderAsync()0%42600%
RequestWearableCollection()0%42600%
RequestWearableCollectionInBuilder()0%42600%
AddWearablesToCatalog(...)0%6200%
RemoveWearablesFromCatalog(...)0%6200%
RemoveWearableFromCatalog(...)0%6200%
RemoveWearablesInUse(...)0%6200%
AddEmbeddedWearablesToCatalog(...)0%220100%
Clear()0%6200%
IsValidWearable(...)0%2100%
<CheckFeatureFlag()0%330100%
CheckFeatureFlag(...)0%2.032080%
SetCurrentService(...)0%3.143075%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/WearablesCatalogServiceProxy.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System.Collections.Generic;
 3using System.Threading;
 4
 5namespace DCLServices.WearablesCatalogService
 6{
 7    /// <summary>
 8    /// This service will choose LambdasWearablesCatalogService or WebInterfaceWearablesCatalogService for requesting
 9    /// wearables depending on the flag 'usingUrlParamsForDebug' received in the kernel configuration.
 10    /// This will be temporal while we have to live with both services.
 11    /// </summary>
 12    public class WearablesCatalogServiceProxy : IWearablesCatalogService
 13    {
 14        private const string FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF = "force_to_request_wearables_through_kernel";
 15
 16        public BaseDictionary<string, WearableItem> WearablesCatalog =>
 017            wearablesCatalogServiceInUse?.WearablesCatalog;
 18
 19        private IWearablesCatalogService wearablesCatalogServiceInUse;
 20        private readonly IWearablesCatalogService lambdasWearablesCatalogService;
 21        private readonly WebInterfaceWearablesCatalogService webInterfaceWearablesCatalogService;
 22        private readonly BaseDictionary<string, WearableItem> wearablesCatalog;
 23        private readonly KernelConfig kernelConfig;
 24        private readonly WearablesWebInterfaceBridge wearablesWebInterfaceBridge;
 25        private readonly BaseVariable<FeatureFlag> featureFlags;
 26        private bool isInitialized;
 27
 11528        public WearablesCatalogServiceProxy(
 29            IWearablesCatalogService lambdasWearablesCatalogService,
 30            WebInterfaceWearablesCatalogService webInterfaceWearablesCatalogService,
 31            BaseDictionary<string, WearableItem> wearablesCatalog,
 32            KernelConfig kernelConfig,
 33            WearablesWebInterfaceBridge wearablesWebInterfaceBridge,
 34            BaseVariable<FeatureFlag> featureFlags)
 35        {
 11536            this.lambdasWearablesCatalogService = lambdasWearablesCatalogService;
 11537            this.webInterfaceWearablesCatalogService = webInterfaceWearablesCatalogService;
 11538            this.wearablesCatalog = wearablesCatalog;
 11539            this.kernelConfig = kernelConfig;
 11540            this.wearablesWebInterfaceBridge = wearablesWebInterfaceBridge;
 11541            this.featureFlags = featureFlags;
 11542        }
 43
 44        public void Initialize()
 45        {
 11546            if (!featureFlags.Get().IsInitialized)
 11547                featureFlags.OnChange += CheckFeatureFlag;
 48            else
 049                CheckFeatureFlag(featureFlags.Get());
 050        }
 51
 52        public void Dispose()
 53        {
 11554            wearablesCatalogServiceInUse?.Dispose();
 055        }
 56
 57        public async UniTask<WearableCollectionsAPIData.Collection[]> GetThirdPartyCollectionsAsync(CancellationToken ca
 58        {
 059            if (!isInitialized)
 060                await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 61
 062            return await lambdasWearablesCatalogService.GetThirdPartyCollectionsAsync(cancellationToken);
 063        }
 64
 65        public async UniTask<(IReadOnlyList<WearableItem> wearables, int totalAmount)> RequestOwnedWearablesAsync(string
 66            NftRarity rarity = NftRarity.None,
 67            NftCollectionType collectionTypeMask = NftCollectionType.All,
 68            ICollection<string> thirdPartyCollectionIds = null, string name = null,
 69            (NftOrderByOperation type, bool directionAscendent)? orderBy = null)
 70        {
 071            if (!isInitialized)
 072                await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 73
 074            return await lambdasWearablesCatalogService.RequestOwnedWearablesAsync(userId, pageNumber, pageSize,
 75                cancellationToken, category, rarity, collectionTypeMask, thirdPartyCollectionIds, name, orderBy);
 076        }
 77
 78        public async UniTask<(IReadOnlyList<WearableItem> wearables, int totalAmount)> RequestOwnedWearablesAsync(string
 79        {
 080            if (!isInitialized)
 081                await UniTask.WaitUntil(() => isInitialized, cancellationToken: ct);
 82
 083            return await wearablesCatalogServiceInUse.RequestOwnedWearablesAsync(userId, pageNumber, pageSize, cleanCach
 084        }
 85
 86        public async UniTask RequestBaseWearablesAsync(CancellationToken ct)
 87        {
 088            if (!isInitialized)
 089                await UniTask.WaitUntil(() => isInitialized, cancellationToken: ct);
 90
 091            await wearablesCatalogServiceInUse.RequestBaseWearablesAsync(ct);
 092        }
 93
 94        public async UniTask<(IReadOnlyList<WearableItem> wearables, int totalAmount)> RequestThirdPartyWearablesByColle
 95        {
 096            if (!isInitialized)
 097                await UniTask.WaitUntil(() => isInitialized, cancellationToken: ct);
 98
 099            return await wearablesCatalogServiceInUse.RequestThirdPartyWearablesByCollectionAsync(userId, collectionId, 
 0100        }
 101
 102        public async UniTask<WearableItem> RequestWearableAsync(string wearableId, CancellationToken ct)
 103        {
 0104            if (!isInitialized)
 0105                await UniTask.WaitUntil(() => isInitialized, cancellationToken: ct);
 106
 0107            return await wearablesCatalogServiceInUse.RequestWearableAsync(wearableId, ct);
 0108        }
 109
 110        public async UniTask<WearableItem> RequestWearableFromBuilderAsync(string wearableId, CancellationToken ct)
 111        {
 0112            if (!isInitialized)
 0113                await UniTask.WaitUntil(() => isInitialized, cancellationToken: ct);
 114
 0115            return await lambdasWearablesCatalogService.RequestWearableFromBuilderAsync(wearableId, ct);
 0116        }
 117
 118        public async UniTask<IReadOnlyList<WearableItem>> RequestWearableCollection(IEnumerable<string> collectionIds,
 119            CancellationToken cancellationToken, List<WearableItem> wearableBuffer = null)
 120        {
 0121            if (!isInitialized)
 0122                await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 123
 0124            return await lambdasWearablesCatalogService.RequestWearableCollection(collectionIds, cancellationToken, wear
 0125        }
 126
 127        public async UniTask<(IReadOnlyList<WearableItem> wearables, int totalAmount)> RequestWearableCollectionInBuilde
 128            IEnumerable<string> collectionIds, CancellationToken cancellationToken,
 129            List<WearableItem> collectionBuffer = null, string nameFilter = null, int pageNumber = 1, int pageSize = 500
 130        {
 0131            if (!isInitialized)
 0132                await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 133
 0134            return await lambdasWearablesCatalogService.RequestWearableCollectionInBuilder(collectionIds, cancellationTo
 135                collectionBuffer, nameFilter, pageNumber, pageSize);
 0136        }
 137
 138        public void AddWearablesToCatalog(IEnumerable<WearableItem> wearableItems) =>
 0139            wearablesCatalogServiceInUse?.AddWearablesToCatalog(wearableItems);
 140
 141        public void RemoveWearablesFromCatalog(IEnumerable<string> wearableIds) =>
 0142            wearablesCatalogServiceInUse?.RemoveWearablesFromCatalog(wearableIds);
 143
 144        public void RemoveWearableFromCatalog(string wearableId) =>
 0145            wearablesCatalogServiceInUse?.RemoveWearableFromCatalog(wearableId);
 146
 147        public void RemoveWearablesInUse(IEnumerable<string> wearablesInUseToRemove) =>
 0148            wearablesCatalogServiceInUse?.RemoveWearablesInUse(wearablesInUseToRemove);
 149
 150        public void AddEmbeddedWearablesToCatalog(IEnumerable<WearableItem> wearables) =>
 11151            wearablesCatalogServiceInUse?.AddEmbeddedWearablesToCatalog(wearables);
 152
 153        public void Clear() =>
 0154            wearablesCatalogServiceInUse?.Clear();
 155
 156        public bool IsValidWearable(string wearableId) =>
 0157            wearablesCatalogServiceInUse.IsValidWearable(wearableId);
 158
 159        private void CheckFeatureFlag(FeatureFlag currentFeatureFlags, FeatureFlag _ = null)
 160        {
 161            async UniTaskVoid SetServiceInUseDependingOnKernelConfig()
 162            {
 40163                var currentKernelConfig = kernelConfig.EnsureConfigInitialized();
 98164                await currentKernelConfig;
 40165                SetCurrentService(currentKernelConfig.value.urlParamsForWearablesDebug);
 40166            }
 167
 40168            featureFlags.OnChange -= CheckFeatureFlag;
 169
 40170            if (currentFeatureFlags.IsFeatureEnabled(FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF))
 0171                SetCurrentService(true);
 172            else
 40173                SetServiceInUseDependingOnKernelConfig().Forget();
 40174        }
 175
 176        private void SetCurrentService(bool useKernel)
 177        {
 40178            if (useKernel)
 179            {
 0180                webInterfaceWearablesCatalogService.Initialize(wearablesWebInterfaceBridge, wearablesCatalog);
 0181                wearablesCatalogServiceInUse = webInterfaceWearablesCatalogService;
 182            }
 183            else
 184            {
 40185                lambdasWearablesCatalogService.Initialize();
 40186                wearablesCatalogServiceInUse = lambdasWearablesCatalogService;
 40187                webInterfaceWearablesCatalogService?.Dispose();
 188            }
 189
 40190            isInitialized = true;
 40191        }
 192    }
 193}