Try our conversational search powered by Generative AI!

Benjamin Schaefer
Apr 13, 2017
  3045
(3 votes)

Working with Episerver Social References

Episerver Social is a stand-alone platform that provides unparalleled control over the construction of models used to deliver social content. Social has two ways to uniquely reference content stored within it.

  • An Id that is generated when a model is persisted into the Social system.
  • A Reference, a means of identifying relationships between social content and application entities.

One aspect of building a maintainable social application is ensuring that you apply a consistent scheme for representing the relationships between your application and its social content. References must be capable of uniquely identifying your application's entities, being easily interpreted by your application, and robust enough to support your application's inevitable future changes.

Example use cases for References might include the following:

  • Referencing a third-party platform that Social is interacting with (for example, Episerver, Ektron, SAP, etc.)
  • Referencing a third-party provider that Social is being used with (for example, Commerce, Cms, ERP, etc.)
  • Referencing unique user Ids
  • Referencing unique product/variant Ids

To ensure the consistent construction of a reference a developer might find it advantageous to standardize the way references are created. Here are three guidelines to help you to create references.

1. Build an easily expandable mechanism for handling strings that will be used most often.

//Outline the standard platforms that will be in use with Social.
public static class Platform
{
    public const string Episerver = "Episerver";
    public const string Ektron = "Ektron";
    public const string Salesforce = "Salesforce";
    public const string SAP = "SAP";
    public const string Microsoft = "Microsoft";
}
//Outline the standard providers that exist for your platforms and will be referenced by your builder. 
public static class Provider
{ 
    //Episever and Ektron
    public const string CMS = "CMS";
    public const string Commerce = "Commerce";
 
    //Salesforce
    public const string Demandware = "Demandware";
    public const string SalesCloud = "SalesCloud";
    public const string Pardot = "Pardot";
 
    //SAP
    public const string ERP = "ERP";
    public const string Anywhere = "Anywhere";
 
    //Microsoft
    public const string Sharepoint = "Sharepoint";
    public const string Dynamics = "Dynamics";
} 

2. Build an efficient way to assemble the relevant strings needed for your Social References.

// This class builds up a string from the relevant details of a product in a third party system.
public class ProductReferenceBuilder
{
    public string Platform { get; set; }
    public string Provider { get; set; }
    public string ProductId { get; set; }
    public string Variant { get; set; }

    public ProductReferenceBuilder AddPlatform(string platform)
    {
        Platform = platform;
        return this;
    }
    
public ProductReferenceBuilder AddProvider(string provider)     {         Provider = provider;         return this;     }
public ProductReferenceBuilder AddProductId(string productId)     {         ProductId = productId;         return this;     }
public ProductReferenceBuilder AddVariantId(string variant)     {         Variant = variant;         return this;     }
  public Reference Build()     {         ProductReferenceValidation();         var referenceString = $"Product://{Platform}/{Provider}/{ProductId}/{Variant}";         return Reference.Create(referenceString);     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(ProductId) ||         string.IsNullOrWhiteSpace(Variant))         {             throw new Exception("Missing field value for ProductReference");         }     }
// This class builds up a string from the relevant details of a user in a third-party system. public class UserReferenceBuilder {     public string Platform { get; set; }     public string Provider { get; set; }     public string UserId { get; set; }
public UserReferenceBuilder AddPlatform(string platform)     {         Platform = platform;         return this;     }
  public UserReferenceBuilder AddProvider(string provider)     {         Provider = provider;         return this;     }
public UserReferenceBuilder AddUserId(string userId)     {         UserId = userId;         return this;     }
public Reference Build()     {         ProductReferenceValidation();         var referenceString = $"User://{Platform}/{Provider}/{UserId}";         return Reference.Create(referenceString);     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(UserId))         {             throw new Exception("Missing field value for UserReference");         }     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(UserId))         {             throw new Exception("Missing field value for UserReference");         }     } }

3. Add unit tests for your reference related classes to ensure that the creation of a reference matches what is expected.

[TestClass]
public class ProductBuilderTest
{
    [TestMethod]
    public void ProductReferenceBuilder_Build_ReturnsProperlyConstructedReference()
    {
         var expectedProductReference = Reference.Create("Product://Episerver/Commerce/ProductId/VarientId");
         var actualProductReference = new ProductReferenceBuilder().AddPlatform(Platform.Episerver)
                                                                   .AddProvider(Provider.Commerce)
                                                                   .AddProductId("ProductId")
                                                                   .AddVariantId("VarientId")
                                                                   .Build();
        Assert.IsTrue(expectedProductReference == actualProductReference);
    }

 

    [TestMethod]
    public void UserReferenceBuilder_Build_ReturnsProperlyConstructedReference()
    {
        var expectedProductReference = Reference.Create("User://Microsoft/Dynamics/UserId");
        var actualProductReference = new UserReferenceBuilder().AddPlatform(Platform.Microsoft)
                                                               .AddProvider(Provider.Dynamics)
                                                               .AddUserId("UserId")
                                                               .Build();
        Assert.IsTrue(expectedProductReference == actualProductReference);
    }
}

By employing these guidelines, developers can create reusable code to help construct references consistently.
Additional information on Episerver Social Reference can be found at:
http://world.episerver.com/documentation/developer-guides/social/social_platform-overview/discovering-the-platform/#referenceandIDs.
 

Apr 13, 2017

Comments

192.168.l.254 192.168.1.254
192.168.l.254 192.168.1.254 Sep 7, 2018 05:29 PM

192.168.l.254

Please login to comment.
Latest blogs
Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024

Optimizely CMS – Getting all content of a specific property with a simple SQL script

When you need to retrieve all content of a specific property from a Page/Block type, normally you will use the IContentLoader or IContentRepository...

Tung Tran | Apr 15, 2024