Skip to content

Commit

Permalink
Merge pull request #8 from codrod/v10.1
Browse files Browse the repository at this point in the history
V10.1.2.0 Updates
  • Loading branch information
Oceanswave authored Jun 30, 2022
2 parents 1ee338d + 716d13f commit 27ab888
Show file tree
Hide file tree
Showing 393 changed files with 9,722 additions and 1,109 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,9 @@ FodyWeavers.xsd
.idea/
*.sln.iml
/package.zip



# Brightcove
Brightcove.Web/App_Config/Include/Unicorn/Unicorn.Configs.Brightcove.config

1 change: 1 addition & 0 deletions Brightcove.Core/Brightcove.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Models\PlayListSearch.cs" />
<Compile Include="Models\TagInclusion.cs" />
<Compile Include="Models\TextTrack.cs" />
<Compile Include="Models\VideoVariant.cs" />
<Compile Include="Models\Video.cs" />
<Compile Include="Models\VideoLink.cs" />
<Compile Include="Models\VideoSharing.cs" />
Expand Down
38 changes: 38 additions & 0 deletions Brightcove.Core/Models/VideoVariant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Brightcove.Core.Models
{
/// <summary>
/// Represents a video object from the Brightcove API
/// For more information, see http://support.brightcove.com/en/video-cloud/docs/media-api-objects-reference#Video
/// </summary>
public class VideoVariant
{
[JsonIgnore]
public string Id { get; set; }

[JsonProperty("language", NullValueHandling = NullValueHandling.Ignore)]
public string Language { get; set; }

[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }

[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)]
public string Description { get; set; }

[JsonProperty("long_description", NullValueHandling = NullValueHandling.Ignore)]
public string LongDescription { get; set; }

[JsonProperty("custom_fields", NullValueHandling = NullValueHandling.Ignore)]
public IDictionary<string, string> CustomFields { get; set; }

public VideoVariant ShallowCopy()
{
return (VideoVariant)this.MemberwiseClone();
}
}
}
126 changes: 126 additions & 0 deletions Brightcove.Core/Services/BrightcoveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ public PlayList CreatePlaylist(string name)
return playlist;
}

public VideoVariant CreateVideoVariant(string videoId, string videoVariantName, string language)
{
VideoVariant videoVariant = new VideoVariant();
videoVariant.Language = language;
videoVariant.Name = videoVariantName;

if (videoId.Contains(","))
{
throw new ArgumentException("the video ID must not contain any commas", nameof(videoId));
}

if (string.IsNullOrWhiteSpace(videoVariantName))
{
throw new ArgumentException("the video name cannnot be null or empty string", nameof(videoVariantName));
}

HttpRequestMessage request = new HttpRequestMessage();
request.Content = new StringContent(JsonConvert.SerializeObject(videoVariant), Encoding.UTF8, "application/json");
request.Method = HttpMethod.Post;
request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants");

HttpResponseMessage response = SendRequest(request);
videoVariant = JsonConvert.DeserializeObject<VideoVariant>(response.Content.ReadAsString());
videoVariant.Id = videoId;

return videoVariant;
}

public void DeletePlaylist(string playlistId)
{
if (string.IsNullOrWhiteSpace(playlistId))
Expand Down Expand Up @@ -143,6 +171,28 @@ public void DeleteVideo(string videoId)
return;
}

public void DeleteVideoVariant(string videoId, string language)
{
if (string.IsNullOrWhiteSpace(videoId))
{
return;
}

if (videoId.Contains(","))
{
throw new ArgumentException("the video ID must not contain any commas", nameof(videoId));
}

HttpRequestMessage request = new HttpRequestMessage();

request.Method = HttpMethod.Delete;
request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants/{language}");

SendRequest(request);

return;
}

public Video UpdateVideo(Video video)
{
HttpRequestMessage request = new HttpRequestMessage();
Expand All @@ -164,6 +214,26 @@ public Video UpdateVideo(Video video)
return JsonConvert.DeserializeObject<Video>(response.Content.ReadAsString());
}

public VideoVariant UpdateVideoVariant(VideoVariant videoVariant)
{
HttpRequestMessage request = new HttpRequestMessage();

request.Method = new HttpMethod("PATCH");
request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoVariant.Id}/variants/{videoVariant.Language}");

//Some properties will cause an invalid response because they are not updateable
//Setting the property to null should remove it from the serialized request
//Use shallowcopy to avoid side-effects caused by mutating the reference
VideoVariant newVideoVariant = videoVariant.ShallowCopy();
newVideoVariant.Language = null;

request.Content = new StringContent(JsonConvert.SerializeObject(newVideoVariant), Encoding.UTF8, "application/json");
HttpResponseMessage response = SendRequest(request);

return JsonConvert.DeserializeObject<VideoVariant>(response.Content.ReadAsString());
}


public Player CreatePlayer(string name, string description)
{
var playerRequest = new { name = name, description = description };
Expand Down Expand Up @@ -251,6 +321,21 @@ public IEnumerable<Video> GetVideos(int offset = 0, int limit = 20, string sort
return JsonConvert.DeserializeObject<List<Video>>(response.Content.ReadAsString());
}

public IEnumerable<VideoVariant> GetVideoVariants(string videoId)
{
HttpRequestMessage request = new HttpRequestMessage();

request.Method = HttpMethod.Get;
request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants");

HttpResponseMessage response = SendRequest(request);

var results = JsonConvert.DeserializeObject<List<VideoVariant>>(response.Content.ReadAsString());
results.ForEach(r => r.Id = videoId);

return results;
}

public PlayerList GetPlayers()
{
HttpRequestMessage request = new HttpRequestMessage();
Expand Down Expand Up @@ -355,6 +440,47 @@ public bool TryGetVideo(string videoId, out Video video)
return true;
}


public bool TryGetVideoVariant(string videoId, string language, out VideoVariant videoVariant)
{
if (string.IsNullOrWhiteSpace(videoId))
{
videoVariant = null;
return false;
}

if (videoId.Contains(","))
{
throw new ArgumentException("the video ID must not contain any commas", nameof(videoId));
}

HttpRequestMessage request = new HttpRequestMessage();
HttpResponseMessage response;

request.Method = HttpMethod.Get;
request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants/{language}");

try
{
response = SendRequest(request);
}
catch (HttpStatusException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
{
videoVariant = null;
return false;
}

throw ex;
}

videoVariant = JsonConvert.DeserializeObject<VideoVariant>(response.Content.ReadAsString());
videoVariant.Id = videoId;

return true;
}

public bool TryGetPlaylist(string playlistId, out PlayList playlist)
{
if (string.IsNullOrWhiteSpace(playlistId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,20 @@
<Compile Include="Converters\PipelineStepWithEndpointFromConverter.cs" />
<Compile Include="Converters\NullableEnumValueReaderConverter.cs" />
<Compile Include="Converters\ReadAssetItemsPipelineStepConverter.cs" />
<Compile Include="Converters\UpdatePipelineStepConverter.cs" />
<Compile Include="Converters\WebApiEndpointConverter.cs" />
<Compile Include="Converters\ResolveAssetItemPipelineStepConverter.cs" />
<Compile Include="Converters\CsvStringPropertyValueAccessorConverter.cs" />
<Compile Include="Converters\VideoIdsPropertyValueAccessorConverter.cs" />
<Compile Include="Converters\StringDictionaryPropertyValueAccessorConverter.cs" />
<Compile Include="Converters\ChainedPropertyValueAccessorConverter.cs" />
<Compile Include="Converters\ResolveOrUpdateAssetModelPipelineStepConverter.cs" />
<Compile Include="Processors\BasePipelineStepWithWebApiEndpointProcessor.cs" />
<Compile Include="Helpers\ItemUpdater.cs" />
<Compile Include="Helpers\Mapper.cs" />
<Compile Include="Helpers\ResolveHelper.cs" />
<Compile Include="Processors\BasePipelineStepProcessor.cs" />
<Compile Include="Processors\BasePipelineStepWithEndpointFromProcessor.cs" />
<Compile Include="Processors\BasePipelineStepWithWebApiEndpointProcessor.cs" />
<Compile Include="Processors\GetExperiencesPipelineStepProcessor.cs" />
<Compile Include="Processors\GetPlayersPipelineStepProcessor.cs" />
<Compile Include="Processors\ReadAssetItemsPipelineStepProcessor.cs" />
Expand All @@ -460,10 +465,13 @@
<Compile Include="Processors\ResolvePlayListModelPipelineStepProcessor.cs" />
<Compile Include="Processors\UpdatePlaylistModelPipelineStepProcessor.cs" />
<Compile Include="Processors\UpdatePlayerModelPipelineStepProcessor.cs" />
<Compile Include="Processors\UpdateVideoItemProcessor.cs" />
<Compile Include="Processors\UpdateVideoModelPipelineStepProcessor.cs" />
<Compile Include="Processors\ResolveVideoModelPipelineStepProcessor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SearchResults\AssetSearchResult.cs" />
<Compile Include="Settings\EndpointsSettings.cs" />
<Compile Include="Settings\MappingSettings.cs" />
<Compile Include="Settings\ResolveAssetItemSettings.cs" />
<Compile Include="Settings\ResolveAssetModelSettings.cs" />
<Compile Include="Settings\WebApiSettings.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
{
base.AddPlugins(source, pipelineStep);

Item endpointItem = Sitecore.Context.ContentDatabase.GetItem(new ID(this.GetGuidValue(source, "BrightcoveEndpoint")));
Guid endpointId = this.GetGuidValue(source, "BrightcoveEndpoint");
ResolveAssetItemSettings resolveAssetItemSettings = new ResolveAssetItemSettings();

ResolveAssetItemSettings resolveAssetItemSettings = new ResolveAssetItemSettings()
if (endpointId != null)
{
AcccountItemId = endpointItem["Account"],
RelativePath = this.GetStringValue(source, "RelativePath")
};
Item endpointItem = Sitecore.Context.ContentDatabase.GetItem(new ID(endpointId));

if(endpointItem != null)
{
resolveAssetItemSettings.AcccountItemId = endpointItem["Account"];
resolveAssetItemSettings.RelativePath = this.GetStringValue(source, "RelativePath") ?? "";
}
}

pipelineStep.AddPlugin<ResolveAssetItemSettings>(resolveAssetItemSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
{
base.AddPlugins(source, pipelineStep);

Item endpointItem = Sitecore.Context.ContentDatabase.GetItem(new ID(this.GetGuidValue(source, "BrightcoveEndpoint")));
Guid endpointId = this.GetGuidValue(source, "BrightcoveEndpoint");
ResolveAssetItemSettings resolveAssetItemSettings = new ResolveAssetItemSettings();

ResolveAssetItemSettings resolveAssetItemSettings = new ResolveAssetItemSettings()
if (endpointId != null)
{
AcccountItemId = endpointItem["Account"],
RelativePath = this.GetStringValue(source, "RelativePath")
};
Item endpointItem = Sitecore.Context.ContentDatabase.GetItem(new ID(endpointId));

if (endpointItem != null)
{
resolveAssetItemSettings.AcccountItemId = endpointItem["Account"];
resolveAssetItemSettings.RelativePath = this.GetStringValue(source, "RelativePath") ?? "";
}
}

pipelineStep.AddPlugin<ResolveAssetItemSettings>(resolveAssetItemSettings);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Brightcove.DataExchangeFramework.Settings;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.DataExchange.Attributes;
using Sitecore.DataExchange.Converters.PipelineSteps;
using Sitecore.DataExchange.DataAccess;
using Sitecore.DataExchange.Models;
using Sitecore.DataExchange.Plugins;
using Sitecore.DataExchange.Providers.Sc.Converters.PipelineSteps;
using Sitecore.DataExchange.Repositories;
using Sitecore.Services.Core.Model;
using System;

namespace Brightcove.DataExchangeFramework.Converters
{
[SupportedIds("{D79A5F5C-9A5E-4B1C-B884-8E3B97CACA2D}", "{F598D123-2FE9-45D3-99E2-3E4B5063190A}")]
public class UpdatePipelineStepConverter : BasePipelineStepConverter
{
public UpdatePipelineStepConverter(IItemModelRepository repository) : base(repository) { }

protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
{
MappingSettings mappingSettings = new MappingSettings()
{
ModelMappingSets = this.ConvertReferencesToModels<IMappingSet>(source, "ModelMappingSets"),
VariantMappingSets = this.ConvertReferencesToModels<IMappingSet>(source, "VariantMappingSets"),
SourceObjectLocation = this.GetGuidValue(source, "SourceObjectLocation"),
TargetObjectLocation = this.GetGuidValue(source, "TargetObjectLocation")
};

pipelineStep.AddPlugin<MappingSettings>(mappingSettings);

BrightcoveEndpointSettings endpointSettings = new BrightcoveEndpointSettings()
{
BrightcoveEndpoint = this.ConvertReferenceToModel<Endpoint>(source, "BrightcoveEndpoint"),
SitecoreEndpoint = this.ConvertReferenceToModel<Endpoint>(source, "SitecoreEndpoint")
};

pipelineStep.AddPlugin<BrightcoveEndpointSettings>(endpointSettings);

Guid endpointId = this.GetGuidValue(source, "BrightcoveEndpoint");

if(endpointId == null)
{
return;
}

ItemModel endpointModel = ItemModelRepository.Get(endpointId);

if(endpointModel == null)
{
return;
}

Guid accountItemId = this.GetGuidValue(endpointModel, "Account");

if(accountItemId == null)
{
return;
}

Item accountItem = Sitecore.Context.ContentDatabase.GetItem(new ID(accountItemId));

if(accountItem == null)
{
return;
}

WebApiSettings webApiSettings = new WebApiSettings();

if (accountItem != null)
{
webApiSettings.AccountId = accountItem["AccountId"];
webApiSettings.ClientId = accountItem["ClientId"];
webApiSettings.ClientSecret = accountItem["ClientSecret"];
}

endpointSettings.BrightcoveEndpoint.AddPlugin(webApiSettings);
}
}
}
Loading

0 comments on commit 27ab888

Please sign in to comment.