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