1 /* 2 * Copyright 2008 FatWire Corporation. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.fatwire.gst.foundation.facade.runtag.commercecontext; 18 19 import COM.FutureTense.Interfaces.ICS; 20 import COM.FutureTense.Interfaces.IList; 21 import COM.FutureTense.Util.IterableIListWrapper; 22 23 import com.fatwire.gst.foundation.IListUtils; 24 import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner; 25 26 /** 27 * Retrieves and lists the assets that match the recommendation constraints 28 * passed to the tag. 29 * <p/> 30 * Syntax 31 * <p/> 32 * <COMMERCECONTEXT.GETRECOMMENDATION COLLECTION="recommendationname" 33 * [LIST="inputlist"] [VALUE="rating"] [MAXCOUNT="assetcount"] 34 * LISTVARNAME="assetlist" [FILTER="true|false"]/> 35 * <p/> 36 * This tag returns a list containing up to the specified number of recommended 37 * assets. The recommendations, and the returned order of them, are based on the 38 * details of the referenced recommendation asset. This tag automatically 39 * calculates segment affinity and promotion affinity for the current visitor, 40 * if they have not yet been calculated. For information about creating 41 * recommendations, including context-based recommendations, see the CS 42 * Developer's Guide. 43 * <p/> 44 * NOTE: This tag also causes compositional dependencies to be recorded for all 45 * assets that contribute to the returned lists, and may, under the right 46 * conditions, have the same effect as a RENDER.UNKNOWNDEPS tag. 47 * 48 * @author Tony Field 49 * @since Apr 12, 2010 50 */ 51 public final class GetRecommendations extends AbstractTagRunner { 52 public GetRecommendations() { 53 super("COMMERCECONTEXT.GETRECOMMENDATIONS"); 54 } 55 56 /** 57 * @param collection Input parameter. Name of the recommendation. The sort 58 * and selection criteria defined in the recommendation are used 59 * to create the list of possible assets. You can constrain this 60 * list by using the MAXCOUNT argument, defined below. If there 61 * are any promotions in place that override this recommendation, 62 * it substitutes the name of the promotion, instead. 63 */ 64 public void setCollection(String collection) { 65 this.set("COLLECTION", collection); 66 } 67 68 /** 69 * @param collectionid ID of the recommendation. The sort and selection 70 * criteria defined in the recommendation are used to create the 71 * list of possible assets. You can constrain this list by using 72 * the MAXCOUNT argument, defined below. If there are any 73 * promotions in place that override this recommendation, it 74 * substitutes the name of the promotion, instead. 75 */ 76 public void setCollectionId(String collectionid) { 77 this.set("COLLECTIONID", collectionid); 78 } 79 80 /** 81 * @param collectionid ID of the recommendation. The sort and selection 82 * criteria defined in the recommendation are used to create the 83 * list of possible assets. You can constrain this list by using 84 * the MAXCOUNT argument, defined below. If there are any 85 * promotions in place that override this recommendation, it 86 * substitutes the name of the promotion, instead. 87 */ 88 public void setCollectionId(long collectionid) { 89 this.setCollectionId(Long.toString(collectionid)); 90 } 91 92 /** 93 * @param inputList Input parameter. name of the list of assets you want to 94 * be used as the input for the calculation. This argument is 95 * applicable only if the recommendation named by COLLECTION is a 96 * context-based recommendation. Columns are assettype and 97 * assetid. 98 */ 99 public void setList(String inputList) { 100 this.set("LIST", inputList); 101 } 102 103 /** 104 * @param rating Input parameter. Default rating for assets that do not have 105 * one. If you do not declare a value, unrated assets are 106 * assigned a default rating of 50 on a scale of 1-100. 107 */ 108 public void setValue(int rating) { 109 this.set("VALUE", Integer.toString(rating)); 110 } 111 112 /** 113 * @param assetcount Input parameter. Maximum number of assets to return. 114 * Use this value to constrain the list of recommended assets. 115 */ 116 public void setMaxCount(int assetcount) { 117 this.set("MAXCOUNT", Integer.toString(assetcount)); 118 } 119 120 /** 121 * @param assetlist Input and output parameter. As input, name you want to 122 * assign to the list of assets returned on output. Its columns 123 * are: assettype and assetid. 124 */ 125 public void setListVarName(String assetlist) { 126 this.set("LISTVARNAME", assetlist); 127 } 128 129 /** 130 * @param filter Input parameter. A Boolean value: true specifies that no 131 * assets in the input list can be returned as output; false 132 * (default) allows input assets to be returned as output. 133 */ 134 public void setFilter(boolean filter) { 135 this.set("FILTER", Boolean.toString(filter).toLowerCase()); 136 } 137 138 /** 139 * Easy-to-use utility method to return recommendations for the specified 140 * asset. 141 * 142 * @param ics context 143 * @param recId id of recommendation to return 144 * @param max max count 145 * @return IList containing recommendations 146 * @see IterableIListWrapper 147 * @deprecated replaced by {@link Recommendations#getRecommendations(ICS, String, int)}. 148 */ 149 @Deprecated 150 public static IList getRecommendations(ICS ics, long recId, int max) { 151 GetRecommendations gr = new GetRecommendations(); 152 gr.setCollectionId(recId); 153 gr.setMaxCount(max); 154 String list = IListUtils.generateRandomListName(); 155 gr.setListVarName(list); 156 gr.execute(ics); 157 IList result = ics.GetList(list); 158 ics.RegisterList(list, null); // unregister 159 return result; 160 } 161 162 }