diff --git a/Brightcove.Core/Services/BrightcoveAuthenticationService.cs b/Brightcove.Core/Services/BrightcoveAuthenticationService.cs index 12efcf88..57c07f63 100644 --- a/Brightcove.Core/Services/BrightcoveAuthenticationService.cs +++ b/Brightcove.Core/Services/BrightcoveAuthenticationService.cs @@ -29,8 +29,8 @@ public BrightcoveAuthenticationService(string clientId, string clientSecret) throw new ArgumentException("argument must not be null or empty", nameof(clientSecret)); } - this.clientId = clientId; - this.clientSecret = clientSecret; + this.clientId = clientId.Trim(); + this.clientSecret = clientSecret.Trim(); } AccessToken GetAccessToken() diff --git a/Brightcove.Core/Services/BrightcoveService.cs b/Brightcove.Core/Services/BrightcoveService.cs index 0e6c008e..ae40cc67 100644 --- a/Brightcove.Core/Services/BrightcoveService.cs +++ b/Brightcove.Core/Services/BrightcoveService.cs @@ -30,7 +30,7 @@ public BrightcoveService(string accountId, string clientId, string clientSecret) throw new ArgumentException("argument must not be null or empty", nameof(accountId)); } - this.accountId = accountId; + this.accountId = accountId.Trim(); authenticationService = new BrightcoveAuthenticationService(clientId, clientSecret); } @@ -513,8 +513,6 @@ public PlayerList GetPlayers() HttpResponseMessage response = SendRequest(request); PlayerList players = JsonConvert.DeserializeObject(response.Content.ReadAsString()); - foreach (var p in players.Items) - p.LastSyncTime = DateTime.UtcNow; return players; } diff --git a/Brightcove.DataExchangeFramework/Brightcove.DataExchangeFramework.csproj b/Brightcove.DataExchangeFramework/Brightcove.DataExchangeFramework.csproj index ca673a6c..716e9643 100644 --- a/Brightcove.DataExchangeFramework/Brightcove.DataExchangeFramework.csproj +++ b/Brightcove.DataExchangeFramework/Brightcove.DataExchangeFramework.csproj @@ -438,44 +438,43 @@ - + - - - - + + + + - - - - - - + + + + + + + - - - - - - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/Brightcove.DataExchangeFramework/Converters/PipelineStepWithEndpointFromConverter.cs b/Brightcove.DataExchangeFramework/Converters/PipelineStep/PipelineStepWithEndpointFromConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/PipelineStepWithEndpointFromConverter.cs rename to Brightcove.DataExchangeFramework/Converters/PipelineStep/PipelineStepWithEndpointFromConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/ReadAssetItemsPipelineStepConverter.cs b/Brightcove.DataExchangeFramework/Converters/PipelineStep/ReadAssetItemsPipelineStepConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/ReadAssetItemsPipelineStepConverter.cs rename to Brightcove.DataExchangeFramework/Converters/PipelineStep/ReadAssetItemsPipelineStepConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/ResolveAssetItemPipelineStepConverter.cs b/Brightcove.DataExchangeFramework/Converters/PipelineStep/ResolveAssetItemPipelineStepConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/ResolveAssetItemPipelineStepConverter.cs rename to Brightcove.DataExchangeFramework/Converters/PipelineStep/ResolveAssetItemPipelineStepConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/ResolveOrUpdateAssetModelPipelineStepConverter.cs b/Brightcove.DataExchangeFramework/Converters/PipelineStep/ResolveOrUpdateAssetModelPipelineStepConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/ResolveOrUpdateAssetModelPipelineStepConverter.cs rename to Brightcove.DataExchangeFramework/Converters/PipelineStep/ResolveOrUpdateAssetModelPipelineStepConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/UpdatePipelineStepConverter.cs b/Brightcove.DataExchangeFramework/Converters/PipelineStep/UpdatePipelineStepConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/UpdatePipelineStepConverter.cs rename to Brightcove.DataExchangeFramework/Converters/PipelineStep/UpdatePipelineStepConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/ChainedPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/ChainedPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/ChainedPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/ChainedPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/CsvStringPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/CsvStringPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/CsvStringPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/CsvStringPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/FolderPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/FolderPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/FolderPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/FolderPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/LabelsPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/LabelsPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/LabelsPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/LabelsPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/StringDictionaryPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/StringDictionaryPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/StringDictionaryPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/StringDictionaryPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Converters/VideoIdsPropertyValueAccessorConverter.cs b/Brightcove.DataExchangeFramework/Converters/ValueAccessor/VideoIdsPropertyValueAccessorConverter.cs similarity index 100% rename from Brightcove.DataExchangeFramework/Converters/VideoIdsPropertyValueAccessorConverter.cs rename to Brightcove.DataExchangeFramework/Converters/ValueAccessor/VideoIdsPropertyValueAccessorConverter.cs diff --git a/Brightcove.DataExchangeFramework/Extensions/ItemModelExtensions.cs b/Brightcove.DataExchangeFramework/Extensions/ItemModelExtensions.cs new file mode 100644 index 00000000..3fe5884b --- /dev/null +++ b/Brightcove.DataExchangeFramework/Extensions/ItemModelExtensions.cs @@ -0,0 +1,24 @@ +using Sitecore.Services.Core.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Brightcove.DataExchangeFramework.Extensions +{ + public static class ItemModelExtensions + { + public static string GetLanguage(this ItemModel model) + { + object language = null; + + if(!model.TryGetValue(ItemModel.ItemLanguage, out language)) + { + language = "en"; + } + + return (string)language; + } + } +} diff --git a/Brightcove.DataExchangeFramework/Helpers/ResolveHelper.cs b/Brightcove.DataExchangeFramework/Helpers/ResolveHelper.cs deleted file mode 100644 index 2f9f8beb..00000000 --- a/Brightcove.DataExchangeFramework/Helpers/ResolveHelper.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Brightcove.DataExchangeFramework.Helpers -{ - class ResolveHelper - { - } -} diff --git a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/BasePipelineStepProcessor.cs index 2eb04641..f08fffaa 100644 --- a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepProcessor.cs +++ b/Brightcove.DataExchangeFramework/Processors/BasePipelineStepProcessor.cs @@ -43,15 +43,13 @@ protected override void ProcessPipelineStep(PipelineStep pipelineStep = null, Pi } catch(Exception ex) { - LogFatal("An unexpected error occured running the pipeline step", ex); - pipelineContext.CriticalError = true; + LogFatal("An unexpected error occured running the internal pipeline step", ex); + pipelineContext.CriticalError = false; } } protected virtual void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) { - LogFatal($"No processor has been defined for the pipeline step"); - pipelineContext.CriticalError = true; return; } @@ -119,7 +117,7 @@ private string GetErrorMessage(string message) private string GetExceptionMessage(Exception ex) { - return $"{ex.GetType()}: {ex.Message}\n{ex.StackTrace}"; + return ex.ToString(); } } } diff --git a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithEndpointFromProcessor.cs b/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithEndpointFromProcessor.cs deleted file mode 100644 index d6ec9b6f..00000000 --- a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithEndpointFromProcessor.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Brightcove.Core.Models; -using Brightcove.Core.Services; -using Brightcove.DataExchangeFramework.Settings; -using Sitecore.DataExchange.Attributes; -using Sitecore.DataExchange.Contexts; -using Sitecore.DataExchange.Converters.PipelineSteps; -using Sitecore.DataExchange.Extensions; -using Sitecore.DataExchange.Models; -using Sitecore.DataExchange.Plugins; -using Sitecore.DataExchange.Processors.PipelineSteps; -using Sitecore.DataExchange.Repositories; -using Sitecore.Services.Core.Diagnostics; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Brightcove.DataExchangeFramework.Processors -{ - public class BasePipelineStepWithEndpointFromProcessor : BasePipelineStepWithEndpointsProcessor - { - protected Endpoint EndpointFrom { get; set; } - - - protected override void ProcessPipelineStep(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) - { - if (pipelineStep == null) - { - throw new ArgumentNullException(nameof(pipelineStep)); - } - if (pipelineContext == null) - { - throw new ArgumentNullException(nameof(pipelineContext)); - } - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - - EndpointSettings endpointSettings = pipelineStep.GetEndpointSettings(); - - if (endpointSettings == null) - { - this.Log(new Action(logger.Error), pipelineContext, "Pipeline step processing will abort because the pipeline step is missing a plugin.", new string[1] - { - "plugin: " + typeof (EndpointSettings).FullName - }); - - pipelineContext.CriticalError = true; - return; - } - - EndpointFrom = endpointSettings.EndpointFrom; - - if (EndpointFrom == null) - { - this.Log(new Action(logger.Error), pipelineContext, "Pipeline step processing will abort because the pipeline step is missing an endpoint to read from.", new string[2] - { - "plugin: " + typeof (EndpointSettings).FullName, - "property: EndpointFrom" - }); - - pipelineContext.CriticalError = true; - return; - } - else if (!this.IsEndpointValid(EndpointFrom, pipelineStep, pipelineContext, logger)) - { - this.Log(new Action(logger.Error), pipelineContext, "Pipeline step processing will abort because the endpoint to read from is not valid.", new string[1] - { - "endpoint: " + EndpointFrom.Name - }); - - pipelineContext.CriticalError = true; - return; - } - } - } -} diff --git a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithWebApiEndpointProcessor.cs b/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithWebApiEndpointProcessor.cs index ccd4301e..224fdac4 100644 --- a/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithWebApiEndpointProcessor.cs +++ b/Brightcove.DataExchangeFramework/Processors/BasePipelineStepWithWebApiEndpointProcessor.cs @@ -22,100 +22,59 @@ namespace Brightcove.DataExchangeFramework.Processors { - public class BasePipelineStepWithWebApiEndpointProcessor : BasePipelineStepWithEndpointFromProcessor + public class BasePipelineStepWithWebApiEndpointProcessor : BasePipelineStepProcessor { protected WebApiSettings WebApiSettings { get; set; } + protected Endpoint EndpointFrom { get; set; } protected override void ProcessPipelineStep(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) { - base.ProcessPipelineStep(pipelineStep, pipelineContext, logger); - - if (pipelineContext.CriticalError) + if (pipelineStep == null) { - return; + throw new ArgumentNullException(nameof(pipelineStep)); } - - WebApiSettings = EndpointFrom.GetPlugin(); - - if (WebApiSettings == null) + if (pipelineContext == null) { - logger.Error( - "No web api settings specified on the endpoint. " + - "(pipeline step: {0})", - pipelineStep.Name); - - pipelineContext.CriticalError = true; - return; + throw new ArgumentNullException(nameof(pipelineContext)); } - - if (string.IsNullOrWhiteSpace(WebApiSettings.AccountId)) + if (logger == null) { - logger.Error( - "No account ID is specified on the endpoint. " + - "(pipeline step: {0})", - pipelineStep.Name); + throw new ArgumentNullException(nameof(logger)); + } + + EndpointSettings endpointSettings = pipelineStep.GetEndpointSettings(); - pipelineContext.CriticalError = true; + if (endpointSettings == null) + { + LogFatal("Pipeline step processing will abort because the pipeline step is missing endpoint settings."); return; } - if (string.IsNullOrWhiteSpace(WebApiSettings.ClientId)) - { - logger.Error( - "No client ID is specified on the endpoint. " + - "(pipeline step: {0})", - pipelineStep.Name); + EndpointFrom = endpointSettings.EndpointFrom; - pipelineContext.CriticalError = true; + if (EndpointFrom == null) + { + LogFatal("Pipeline step processing will abort because the pipeline step is missing an endpoint to read from."); return; } - if (string.IsNullOrWhiteSpace(WebApiSettings.ClientSecret)) - { - logger.Error( - "No client secret is specified on the endpoint. " + - "(pipeline step: {0})", - pipelineStep.Name); + WebApiSettings = GetPluginOrFail(EndpointFrom); - pipelineContext.CriticalError = true; + if(!WebApiSettings.Validate()) + { + LogFatal("Pipeline step processing will abort because the Brightcove web API settings are invalid: "+WebApiSettings.ValidationMessage); return; } - } - public void SetFolderSettings(string folderName) - { - Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); - Sitecore.Data.Items.Item node = masterDB.GetItem("/sitecore/media library/BrightCove/BrightCove Account/"+ folderName); - if (node == null) + try { - Sitecore.Data.Items.Item parentNode = masterDB.GetItem("/sitecore/media library/BrightCove/BrightCove Account"); - Sitecore.Data.Items.Item folder = masterDB.GetItem("/sitecore/templates/Common/Folder"); - parentNode.Add(folderName, new TemplateItem(folder)); - - node = masterDB.GetItem("/sitecore/media library/BrightCove/BrightCove Account/"+ folderName); - using (new Sitecore.Data.Items.EditContext(node, SecurityCheck.Disable)) - { - IsBucketItemCheckBox(node).Checked = true; - } + ProcessPipelineStepInternal(pipelineStep, pipelineContext, logger); } - else + catch (Exception ex) { - using (new Sitecore.Data.Items.EditContext(node, SecurityCheck.Disable)) - { - if (!IsBucketItemCheck(node)) - IsBucketItemCheckBox(node).Checked = true; - } + LogFatal("An unexpected error occured running the internal pipeline step", ex); + pipelineContext.CriticalError = false; } } - - public bool IsBucketItemCheck(Item item) - { - return (((item != null) && (item.Fields[Sitecore.Buckets.Util.Constants.IsBucket] != null)) && item.Fields[Sitecore.Buckets.Util.Constants.IsBucket].Value.Equals("1")); - } - - public CheckboxField IsBucketItemCheckBox(Item item) - { - return item.Fields[Sitecore.Buckets.Util.Constants.IsBucket]; - } } } diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetExperiencesPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetExperiencesPipelineStepProcessor.cs new file mode 100644 index 00000000..377b0fff --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetExperiencesPipelineStepProcessor.cs @@ -0,0 +1,38 @@ +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.Data.Fields; +using Sitecore.Data.Items; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.SecurityModel; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Linq; + +namespace Brightcove.DataExchangeFramework.Processors +{ + class GetExperiencesPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + var data = service.GetExperiences().Items; + var dataSettings = new IterableDataSettings(data); + + LogDebug("Read " + data.Count() + " experience model(s) from web API"); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + } +} diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetFoldersPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetFoldersPipelineStepProcessor.cs new file mode 100644 index 00000000..89a73471 --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetFoldersPipelineStepProcessor.cs @@ -0,0 +1,50 @@ +using Brightcove.Core.Models; +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.DataExchange.Attributes; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Converters.PipelineSteps; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.DataExchange.Processors.PipelineSteps; +using Sitecore.DataExchange.Repositories; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Brightcove.DataExchangeFramework.Processors +{ + public class GetFoldersPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + var folders = service.GetFolders(); + + foreach (Folder folder in folders) + { + folder.LastSyncTime = DateTime.UtcNow; + } + + LogDebug("Read " + folders.Count() + " folder model(s) from web API"); + + var dataSettings = new IterableDataSettings(folders); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + } +} diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetLabelsPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetLabelsPipelineStepProcessor.cs new file mode 100644 index 00000000..23ad8534 --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetLabelsPipelineStepProcessor.cs @@ -0,0 +1,50 @@ +using Brightcove.Core.Models; +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.DataExchange.Attributes; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Converters.PipelineSteps; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.DataExchange.Processors.PipelineSteps; +using Sitecore.DataExchange.Repositories; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Brightcove.DataExchangeFramework.Processors +{ + public class GetLabelsPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + var labels = service.GetLabels(); + + foreach (Label label in labels) + { + label.LastSyncTime = DateTime.UtcNow; + } + + LogDebug("Read " + labels.Count() + " label model(s) from web API"); + + var dataSettings = new IterableDataSettings(labels); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + } +} diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetPlayListsPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetPlayListsPipelineStepProcessor.cs new file mode 100644 index 00000000..8eaf67b7 --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetPlayListsPipelineStepProcessor.cs @@ -0,0 +1,60 @@ +using Brightcove.Core.Models; +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.ContentSearch; +using Sitecore.Data.Items; +using Sitecore.DataExchange.Attributes; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.DataExchange.Processors.PipelineSteps; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Brightcove.DataExchangeFramework.Processors +{ + class GetPlayListsPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + int totalCount = 0; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + totalCount = service.PlayListsCount(); + LogDebug("Read " + totalCount + " playlist model(s) from web API"); + + var data = this.GetIterableData(WebApiSettings, pipelineStep); + var dataSettings = new IterableDataSettings(data); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + + protected virtual IEnumerable GetIterableData(WebApiSettings settings, PipelineStep pipelineStep) + { + int limit = 100; + + for (int offset = 0; offset < totalCount; offset += limit) + { + foreach(PlayList playList in service.GetPlayLists(offset, limit)) + { + playList.LastSyncTime = DateTime.UtcNow; + yield return playList; + } + } + } + } +} diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetPlayersPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetPlayersPipelineStepProcessor.cs new file mode 100644 index 00000000..58e69a4e --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetPlayersPipelineStepProcessor.cs @@ -0,0 +1,44 @@ +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.Data.Fields; +using Sitecore.Data.Items; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.SecurityModel; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Linq; + +namespace Brightcove.DataExchangeFramework.Processors +{ + class GetPlayersPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + var data = service.GetPlayers().Items; + + foreach (var player in data) + { + player.LastSyncTime = DateTime.UtcNow; + } + + var dataSettings = new IterableDataSettings(data); + + LogDebug("Read " + data.Count() + " player model(s) from web API"); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + } +} diff --git a/Brightcove.DataExchangeFramework/Processors/Get/GetVideosPipelineStepProcessor.cs b/Brightcove.DataExchangeFramework/Processors/Get/GetVideosPipelineStepProcessor.cs new file mode 100644 index 00000000..152bf2a9 --- /dev/null +++ b/Brightcove.DataExchangeFramework/Processors/Get/GetVideosPipelineStepProcessor.cs @@ -0,0 +1,62 @@ +using Brightcove.Core.Models; +using Brightcove.Core.Services; +using Brightcove.DataExchangeFramework.Settings; +using Sitecore.ContentSearch; +using Sitecore.Data.Items; +using Sitecore.DataExchange.Attributes; +using Sitecore.DataExchange.Contexts; +using Sitecore.DataExchange.Converters.PipelineSteps; +using Sitecore.DataExchange.Models; +using Sitecore.DataExchange.Plugins; +using Sitecore.DataExchange.Processors.PipelineSteps; +using Sitecore.DataExchange.Repositories; +using Sitecore.Services.Core.Diagnostics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Brightcove.DataExchangeFramework.Processors +{ + public class GetVideosPipelineStepProcessor : BasePipelineStepWithWebApiEndpointProcessor + { + BrightcoveService service; + int totalCount = 0; + + protected override void ProcessPipelineStepInternal(PipelineStep pipelineStep = null, PipelineContext pipelineContext = null, ILogger logger = null) + { + try + { + service = new BrightcoveService(WebApiSettings.AccountId, WebApiSettings.ClientId, WebApiSettings.ClientSecret); + + totalCount = service.VideosCount(); + LogDebug("Read " + totalCount + " video model(s) from web API"); + + var data = GetIterableData(pipelineStep); + var dataSettings = new IterableDataSettings(data); + + pipelineContext.AddPlugin(dataSettings); + } + catch (Exception ex) + { + LogError($"Failed to get the brightcove models because an unexpected error has occured", ex); + } + } + + protected virtual IEnumerable