5

I am new to Tridion. I have a doubt regarding my code. I am trying to fetch the promotion from SmartTarget in my Java app, by using SmartTarget 2014 API. I am getting the "Universe cannot be null or empty Exception" in the code on line 4.

To instantiate the Query Builder class, I have used the

QueryBuilder builder = new QueryBuilder(publication, regions)

instead of

QueryBuilder builder = new QueryBuilder(universe, locale) constructor 

as I am not aware of what a Universe is and not sure about what parameter to pass.

Kindly provide some inputs. Some pointers would be really useful.

List<String> regionList = new ArrayList<String>();
regionList.add("Homepage Banners");
regionList.add("Homepage Promotions");
QueryBuilder builder = new QueryBuilder(new TcmUri(PublicationID), regionList);
ClaimStore claims = AmbientDataContext.getCurrentClaimStore();
if (claims != null) {

    Map<URI, Object> x = claims.getAll();
    for (Map.Entry<URI, Object> entry : x.entrySet()) {
        System.out.println("\"KEY\"  " + entry.getKey()
                + " \"Value\"  " + entry.getValue());

    }
}
String triggers = AmbientDataHelper.getTriggers(claims);
System.out.println(triggers);

builder.parseQueryString(triggers);
builder.addCriteria(new RegionCriteria("Homepage Promotions"));
builder.addCriteria(new PublicationCriteria(new TcmUri("PublicationID")));

ResultSet fredHopperResultset = builder.execute();
List<Promotion> promoList = fredHopperResultset.getPromotions();

for (Iterator iterator = promoList.iterator(); iterator.hasNext();) {
    Promotion promotion = (Promotion) iterator.next();

    List<Item> itemList = promotion.getItems();

    for (Item loopItem : itemList) {

        System.out.println(loopItem.getPromotionID());

    }

}
3

The Universe is a Fredhopper concept.

SmartTarget config

The universe is set in the smarttarget_conf.xml

<Fredhopper>
    <DefaultUniverse>catalog01</DefaultUniverse>

The QueryBuilder will read this configuration if you contruct the builder with one of:

  • QueryBuilder()
  • QueryBuilder(TcmUri publication, java.util.List<java.lang.String> regions) (you are using the latter)

Fredhopper

To check if the Fredhopper universe exists:

  1. Browse to the Fredhopper Business Manager (GUI), i.e. http://localhost:8180/fredhopper/admin/ (hostname and port may vary)
  2. Check the available universe names. In a SmartTarget setup I expect only one universe.

enter image description here

Conclusion

Conclusion: Your code should work if this parameter is set in the configuration and if the universe exists in Fredhopper.

Note

Your code declares the regions twice, once in

 List<String> regionList = new ArrayList<String>();
 regionList.add("Homepage Banners");
 regionList.add("Homepage Promotions");
 QueryBuilder builder = new QueryBuilder(new TcmUri(PublicationID), regionList);

and then in

 builder.addCriteria(new RegionCriteria("Homepage Promotions"));
 builder.addCriteria(new PublicationCriteria(new TcmUri("PublicationID")));

You only need to do this once ;-)

2
  • Hi Jan, I am getting the FredHopper Resultset (fredHopperResultset variable above) value as null while there are promotions that exist in Fredhopper for HomePage Promotions Category because of which I am getting a NullPointer Exception. Can you provide some pointers on what might be wrong. Thanks Dec 29 '14 at 4:49
  • The result Set should not be null. Even if there are no promotions returned by the query there should be items returned, and if there are no items published to Fredhopper the resultSet object should not be null. Check the CD SmartTarget and core logs. Post a new question with what you find in the log.
    – Jan H
    Dec 29 '14 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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