Showing posts with label Tridion 2013. Show all posts
Showing posts with label Tridion 2013. Show all posts

Monday, February 3, 2014

Context Expression Extension

I this post I will cover a brand new feature added in Tridion 2013 SP1 called Context Expression Extension (CEE). CEE is part of Tridion 2013 SP1 and is installed as a GUI Extension that will mark Target Groups as Context Expressions. Additionally it has Content Delivery pieces that will be described later in this post.

CEE integrates SDL Tridion with Campaign Management and Analysis Data (CMA) allowing marketers and data analysts to define Expressions in CMA and push them into Tridion in the form of Target Groups. Context Expression Target Groups are read only and can just be updated in CMA, as a personal quote for future releases it would be nice if we can generate Context Expressions from external systems or within the Tridion user interface.

CEE updates how a Target Group looks like if it recognizes that it contains a Context Expression as you can appreciate in the following pictures.








Context Expressions Target Groups are named in the form of [aspect].[property]













CEE will show an extra tab called Context Expression that shows the Expression in read only mode.

Publishing Context Expressions

Context Expressions integrates perfectly with Context Engine Cartridge (CEC) providing access to the Expression in the Presentation Server by publishing the Context Expression Target Group using a new feature called Dynamic Vocabulary. So you may be thinking what is a dynamic vocabulary and what is an static vocabulary instead? Well I will try to explain it. I will call a static vocabulary to the set of expressions that are configured in the cwd_engine_vocabulary_conf.xml. So what is a dynamic vocabulary? Well it is the set of expressions that are published from Tridion (Target Groups Publishing).

You might be asking where are those expressions published, well they are pushed to the Ambient Data Framework (ADF) making them available as claims and eventually available for Tags like If or Eval

Targeting Component Presentations using Context Expressions

The process to target Component Presentations is the same to the one used with P&P (Personalization & Profiling), it is done in the Page - Component Presentations tab. Below a sample.




















After publishing the Page you will see content like the following.

<context:If Expression="(os.apple)" runat="server">
    <span>
        <!-- Start Component Presentation: {"ComponentID" : "tcm:5-2051", "ComponentModified" : "2014-02-03T19:39:54", "ComponentTemplateID" : "tcm:5-1058-32", "ComponentTemplateModified" : "2013-12-26T16:18:55", "IsRepositoryPublished" : false } -->
        <div>

            <h2>
                <span>
                    <!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:Heading[1]"} -->
                    <h1><strong>Article For Apple Devices
                    </strong></h1>
                </span>
            </h2>



            <p>
                <span>
                    <!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:Description[1]"} -->
                    This is a description for <strong>Article For Apple Devices.</strong>
                </span>
            </p>

        </div>
    </span>
</context:If>
<context:If Expression="(os.notapple)" runat="server">
    <span>
        <!-- Start Component Presentation: {"ComponentID" : "tcm:5-51", "ComponentModified" : "2014-02-03T17:59:54", "ComponentTemplateID" : "tcm:5-1058-32", "ComponentTemplateModified" : "2013-12-26T16:18:55", "IsRepositoryPublished" : false } -->
        <div>

            <h2>
                <span>
                    <!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:Heading[1]"} -->
                    <h1>This is a Non Apple Devices Article
                    </h1>
                </span>
            </h2>



            <p>
                <span>
                    <!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:Description[1]"} -->
                    This is a description for Non Apple Devices
                </span>
            </p>

        </div>
    </span>
</context:If>

A Context Expression Target Group is transformed in a <context:if> tag by a TCDL Tag Transformed that is configured in the Deployer.

<TCDLEngine>
                <Properties>
                                <Property Name="tcdl.dotnet.style" Value="controls"/>
                                <Property Name="tcdl.jsp.style" Value="tags"/>
                </Properties>
               
                <TagBundle Resource="com/sdl/context/transformer/contextTagTransformerBundle.xml" />
</TCDLEngine>

The final result is shown below (Please note that in order to have your web application working you have to have a Context Engine Cartridge configured and working).

Non Apple Device Result



Apple Device Result


          

Tuesday, December 10, 2013

Tridion 2013 SP1 - Synchronizing components

Continuing with my posts about Tridion 2013 SP1, I will talk about the new Synchronization API. This API that is available via the Core Services making this API easy to use and very light.

The new synchronization functionality will analyze the component content and the schema and it will infer which operations need to be completed in order to keep them in sync.

Sample:

private static CoreServiceClient channel { get; set; }

using (channel = new CoreServiceClient("basicHttp_2013"))
    try {
        SynchronizeComponent("tcm:5-2051", true);
    }
    finally {
        if (channel.State != CommunicationState.Closed) {
            channel.Close();
        }
    }
}

public static void SynchronizeComponent(string componentId, bool updateAfterSynchronize) {
    Console.WriteLine("Starting Sychronization...");

    SynchronizeOptions options = new SynchronizeOptions() {
        SynchronizeFlags = SynchronizeFlags.All
    };

    SynchronizationResult result;
    if (updateAfterSynchronize) {
        result = channel.SynchronizeWithSchemaAndUpdate(componentId, options);
    }
    else {
        IdentifiableObjectData item = channel.Read(componentId, new ReadOptions());
        result = channel.SynchronizeWithSchema(item, options);
    }

    foreach(SynchronizationActionData action in result.SynchronizationActions) {
        Console.WriteLine();

        Console.WriteLine("Field Name: {0}", action.FieldName);
        Console.WriteLine("Field Index: {0}", action.FieldIndex);
        Console.WriteLine("Action Taken: {0}", action.SynchronizationActionApplied);

        Console.WriteLine();
    }

    Console.WriteLine("Sychronization completed.");
    Console.ReadLine();
}

The first thing we need to consider while writing a synchronizing program would be the Synchronization Options, basically the Synchronization flags.

SynchronizeFlags.All
SynchronizeFlags.ApplyDefaultValuesForMissingMandatoryFields
SynchronizeFlags.ApplyDefaultValuesForMissingNonMandatoryFields
SynchronizeFlags.ApplyFilterXsltToXhtmlFields
SynchronizeFlags.Basic
SynchronizeFlags.ConvertFieldType
SynchronizeFlags.FixNamespace
SynchronizeFlags.RemoveAdditionalValues
SynchronizeFlags.RemoveUnknownFields
SynchronizeFlags.UnknownByClient

You must be careful while using those flags since some of them like  RemoveUnknownFields that will lead you to lose data if is not used carefully.

Other important feature in this new API is the fact that this will return feedback in the form of SynchronizationActionData objects. As you can see in the sample above it will give you information like the FileName, FileIndex and the action that was taken.

You may also notice that in the sample above I am using two different methods SycnrhonizeWithSchema and SynchronizeWithSchemaAndUpdate, the difference is clear, the first one won’t check in any changes and the second one will check in the changes leading you to lose data if not used carefully.

Tridion 2013 SP1 - API improvements

Continuing with my Tridion 2013 SP1 posts I will talk about some API improvements. Below a list containing API improvements.

StreamDownload endpoint can now download external items

Sample:
private static StreamDownloadClient downloadChannel { get; set; }

using (downloadChannel = new StreamDownloadClient("streamDownload_basicHttp_2013")) {
    try {
Stream stream = downloadChannel.DownloadExternalBinaryContent("http://www.sdl.com/Content/themes/common/images/sdl-logo.png");
MemoryStream ms = new MemoryStream();

int b;
while ((b = stream.ReadByte()) != -1) {
ms.WriteByte((byte)b);
}

using (FileStream fs = new FileStream("C:\\sdl-logo.png", FileMode.OpenOrCreate, FileAccess.ReadWrite))
using (BinaryWriter writer = new BinaryWriter(fs)) {
    try {
               writer.Write(ms.ToArray());
    } finally {
        writer.Close();
        fs.Close();
        ms.Close();
    }
}
    }
    finally {
        if (downloadChannel.State != CommunicationState.Closed) {
            downloadChannel.Close();
        }
    }
}

Schemas can be retrieved by Namespace

This is a change in both Core Services and TOM .NET APIs. In this post I will show a Core Service sample.

Sample:

private static CoreServiceClient channel { get; set; }

using (channel = new CoreServiceClient("basicHttp_2013"))
    try {
SchemaData schema = GetSchemaFromNamespace();
    }
    finally {
        if (channel.State != CommunicationState.Closed) {
            channel.Close();
        }
    }
}  

public static SchemaData GetSchemaFromNamespace() {
    LinkToSchemaData schema = channel.GetSchemasByNamespaceUri(PublicationId, "http://www.tridion.com/ContentManager/5.0/DefaultMultimediaSchema", null).FirstOrDefault();
    if (schema != null) {
        return (SchemaData)channel.Read(schema.IdRef, new ReadOptions());
    }
    return null;
}

This change is very important since now we can retrieve schemas by using namespaces (XML like functionality) without having the need to specify tcm uris or webdav urls.

Multimedia Components can be created without specifying a Multimedia Type

This is an small change but it will save you several lines of code J, if the file extension that you are using to create the multimedia component can be mapped to an existing multimedia type, then the API will do it for you.

Sample:

private static CoreServiceClient channel { get; set; }

using (channel = new CoreServiceClient("basicHttp_2013"))
    try {
SchemaData schema = GetSchemaFromNamespace();
CreateMultimediaComponent(schema);
    }
    finally {
        if (channel.State != CommunicationState.Closed) {
            channel.Close();
        }
    }
}  

public static void CreateMultimediaComponent(SchemaData schema) {
    ComponentData multimediaComponent = new ComponentData() {
        Id = TcmUri.UriNull.ToString(),
        Title = Guid.NewGuid().ToString(),
        Schema = new LinkToSchemaData() { IdRef = schema.Id },
        LocationInfo = new LocationInfo() { OrganizationalItem = new LinkToOrganizationalItemData() { IdRef = FolderId } },
        ComponentType = ComponentType.Multimedia,
        BinaryContent = new BinaryContentData() {
            Filename = "sdl-logo.png",
            UploadFromFile = "C:\\sdl-logo.png"
        }
    };

    channel.Create(multimediaComponent, new ReadOptions());
}

Decommissioning Publication Targets

This is a very important change, and it will allow us to mark items that were published to a publication target as unpublished to that publication target in one single operation. It is useful in case you have a publication target that is no longer used and can block other items to be deleted or moved.

Sample:

public static void DecommissioningPublicationTarget(string publicationTargetId) {
    channel.DecommissionPublicationTarget(publicationTargetId);
}