2

I'm following up on Adding a Date option to Session Footprint and Ambient Data Framework Documentation for SDL Tridion 2011.

Specifically I'm trying to follow this excellent answer (thanks much, Peter!).

My setup has SDL Tridion 2011 (with SmartTarget), Fredhopper, and Experience Manager with Session Preview as seen in cd_ambient_conf.xml:

<Cartridge File="cd_webservice_preview_cartridge.xml"/>
<Cartridge File="footprint_cartridge_conf.xml"/>
<Cartridge File="date_cartridge.xml"/><!-- custom -->       
<Cartridge File="smarttarget_cartridge_conf.xml"/>

I'm able to add new claims with a custom XPM Footprint setting and through the following.

public class DateWebClaimProcessor extends AbstractClaimProcessor {

    @Override
    public void onRequestStart(ClaimStore claimStore)
        throws AmbientDataException {
            try {

            DateFormat formatter = new SimpleDateFormat("yyyyMMdd");

            Date today = new Date();
            claimStore.put(new URI("fh:today:date"), today);

            if (claimStore.contains(new URI("fh:user:date")))
                {
                // won't run -- claim processor currently runs out of order, maybe?
                String claimdate = claimStore.get(new URI("fh:user:date")).toString();

                Date date = formatter.parse(claimdate);
                claimStore.put(new URI("fh:converted:date"), date);
                }
            }
            catch (Exception ex) {
                throw new AmbientDataException(ex);
            }
    }

After choosing a specific footprint date and using the ClaimStore page example I have:

fh:today:date 12/5/2013 12:53:12 AM (added by above)

fh:user:date 2012-11-01T00:00:00 (added by Footprint setting)

But I don't get fh:converted:date. I think I need to confirm the order of my cartridges and see that the Order of execution for ADF cartridges is (partly?) based on OutputClaim and InputClaim definitions in Cartridges.

How can I tell what order Session Preview, SmartTarget, and the Footprint run? Is there an expected order or should I check the logs? I'm trying to visual this diagram but with XPM, ST, and FH. :-)

My custom footprint isn't really in the footprint_cartridge_conf.xml as an OutputClaim (in footprint_cartridge.jar), so maybe I'm on the wrong track?

Functionally, I'm trying to get a date set in the footprint recognized by SmartTarget to get date-based campaigns to show in XPM.

2 Answers 2

4

Try the following, it worked for me:

In your cartridge configuration xml e.g. date_cartridge.xml

<ClaimDefinition Uri="fh:user:date" Scope="SESSION" Description="website visit date within the context." /> 

...

<ClaimProcessorDefinition Uri="taf:pe:claimprocessor:context:date"
        ImplementationClass="com.tridion.extensions.ambientdata.DateClaimProcessor"
        Description="Sets the website visit Date">
  <RequestStart>
    <InputClaims>
        <ClaimDefinition Uri="taf:claim:context:date" />
    </InputClaims>
    <OutputClaims>
      <ClaimDefinition Uri="fh:user:date" />
    </OutputClaims>
  </RequestStart>
</ClaimProcessorDefinition>

Here is the Claim Processor class DateClaimProcessor.java

package com.tridion.extensions.ambientdata;

import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tridion.ambientdata.AmbientDataException;
import com.tridion.ambientdata.claimstore.ClaimStore;
import com.tridion.ambientdata.claimstore.ClaimType;
import com.tridion.ambientdata.processing.AbstractClaimProcessor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateClaimProcessor extends AbstractClaimProcessor {
private static final Logger log = LoggerFactory.getLogger(DateClaimProcessor.class);    
public static final String DATE_CLAIM_URI = "fh:user:date";
    public static final String CONTEXT_DATE_CLAIM_URI = "taf:claim:context:date";
public static final URI DATE_URI = URI.create(DATE_CLAIM_URI);
    public static final URI CONTEXT_DATE_URI = URI.create(CONTEXT_DATE_CLAIM_URI);

public DateClaimProcessor() {
    log.debug("DateClaimProcessor: called");
}

@Override
public void onRequestStart(ClaimStore claimStore) throws AmbientDataException {
    log.debug("DateClaimProcessor.onRequestStart: Called");

            if(claimStore.contains(CONTEXT_DATE_URI))
            {
                log.debug("DateClaimProcessor ClaimStore contains " + CONTEXT_DATE_CLAIM_URI);
                //get the date claim and set it as Date object instead of string
                String dateString = claimStore.get(CONTEXT_DATE_URI).toString();
                if(dateString!=null)
                {
                    log.debug("DateClaimProcessor date=" + dateString);
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                    Date date =null;
                   try{
                    date = df.parse(dateString);
                   }
                   catch(Exception e)
                   {
                       log.error("DateClaimProcessor error - " + e.getMessage());
                   }
                    if(date!=null)
                    {                            
                        log.debug("DateClaimProcessor adding fh:user:date as date object=" + new SimpleDateFormat("yyyyMMdd").format(date));
                        claimStore.put(DATE_URI, date);
                    }
                }
            }
}
}

Set the custom claim in SiteEditModel.config:

<footprint ID="visitDate" claimUri="taf:claim:context:date" >
            <title>
                <value lang="1033">Visit Date</value>
            </title>
            <description>
                <value>Select a date for viewing the website as it would look on that date.</value>
            </description>
            <settings>
                <isMandatory>true</isMandatory>
            </settings>                                           
        </footprint>

Set the corresponding footprint in SiteEditEditor.config (as you did before):

<footprint ID="visitDate" controlID="FootprintDate" Icon="calendar"/>

This basically uses a custom date claim which is set by the XPM footprint, and if that claim exists the cartridge actually creates the fh:user:date claim as a date object so it gets recognized by FH properly.

1

There are indeed a couple of problems with this approach:

  1. You should use full URIs in the Claim Store (which are then transformed using the prefixes in SmartTarget). For instance, you might use a URI like "taf:claim:ambientdata:datecartridge:user:date" and configure "fh" as the prefix for "taf:claim:ambientdata:datecartridge" in smarttarget_conf.xml. This isn't stopping it from working, I just wanted to point out the recommended naming convention.
  2. I didn't notice that you were on version which has this functionality in a cartridge (in newer versions it's in the framework itself). You can force your cartridge to run after the footprint cartridge, by setting one of its output claims (for instance 'taf:claim:ambientdata:footprintcartridge:acceptlanguage') as an input claim to your cartridge.

You cannot rely on the order of the cartridges except through this means of dependency management. I don't believe the order of cartridges is explicitly logged anywhere, but likely each cartridge would log something so you can see the order that way.

1
  • Ah, so the dependency doesn't need to be a specific claim. I missed that point. Thanks for the naming convention clarification, that was my next question. I knew enough to at least change Jaime's "jsa:" prefix. :-) Commented Dec 5, 2013 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.