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 com.fatwire.gst.foundation.facade.runtag.assetset;
18  
19  import java.util.List;
20  
21  import COM.FutureTense.Interfaces.ICS;
22  
23  import com.fatwire.assetapi.data.AssetId;
24  import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
25  import com.fatwire.gst.foundation.facade.runtag.listobject.AddRow;
26  import com.fatwire.gst.foundation.facade.runtag.listobject.Create;
27  import com.fatwire.gst.foundation.facade.runtag.listobject.ToList;
28  
29  /**
30   * <assetset:getmultiplevalues name="myassetset" prefix="ValueList"
31   * list="listout" immediateonly="false" byasset="true"/>
32   * 
33   * @author Tony Field
34   * @since Oct 24, 2008
35   */
36  public final class GetMultipleValues extends AbstractTagRunner {
37      public GetMultipleValues() {
38          super("ASSETSET.GETMULTIPLEVALUES");
39      }
40  
41      public void setName(String name) {
42          set("NAME", name);
43      }
44  
45      public void setPrefix(String prefix) {
46          set("PREFIX", prefix);
47      }
48  
49      public void setImmediateOnly(boolean b) {
50          set("IMMEDIATEONLY", b ? "true" : "false");
51      }
52  
53      public void setByAsset(boolean b) {
54          set("BYASSET", b ? "true" : "false");
55      }
56  
57      public void setList(String inputSortListName) {
58          set("LIST", inputSortListName);
59      }
60  
61      public static void getMultipleValues(ICS ics, AssetId id, String prefix, String attrType, List<String> columns) {
62          getMultipleValues(ics, id, null, null, false, false, prefix, attrType, columns);
63      }
64  
65      public static void getMultipleValues(ICS ics, AssetId id, String deptype, String locale, boolean byAsset,
66              boolean immediateOnly, String prefix, String attrType, List<String> columns) {
67          // create asset set
68          SetAsset setAsset = new SetAsset();
69          final String assetSetName = "__AssetSet" + ics.genID(true);
70          setAsset.setName(assetSetName);
71          setAsset.setType(id.getType());
72          setAsset.setId(Long.toString(id.getId()));
73          if (deptype != null) {
74              setAsset.setDeptype(deptype);
75          }
76          if (locale != null) {
77              setAsset.setLocale(locale);
78          }
79          setAsset.execute(ics);
80  
81          // sort list cols first
82          Create createSortList = new Create();
83          final String sortListObjectName = "__SortList" + ics.genID(true);
84          createSortList.setName(sortListObjectName);
85          createSortList.setColumns("attributetypename,attributename,direction");
86          createSortList.execute(ics);
87  
88          // add rows to sort list
89          for (String col : columns) {
90              AddRow addRow = new AddRow();
91              addRow.setName(sortListObjectName);
92              addRow.setColumnValue("attributetypename", attrType);
93              addRow.setColumnValue("attributename", col);
94              addRow.setColumnValue("direction", "ascending");
95              addRow.execute(ics);
96          }
97  
98          final String sortListIListName = "__sortListIList" + ics.genID(true);
99          ToList toList = new ToList();
100         toList.setName(sortListObjectName);
101         toList.setListVarName(sortListIListName);
102         toList.execute(ics);
103 
104         // get values
105         GetMultipleValues gmv = new GetMultipleValues();
106         gmv.setName(assetSetName);
107         gmv.setByAsset(byAsset);
108         gmv.setImmediateOnly(immediateOnly);
109         gmv.setList(sortListIListName);
110         gmv.setPrefix(prefix);
111         gmv.execute(ics);
112     }
113 
114 }