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