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.FutureTense.Interfaces.IList;
21 import com.fatwire.assetapi.data.AssetId;
22 import tools.gsf.facade.runtag.AbstractTagRunner;
23
24 /**
25 * Wrapper around the ASSETSET.GETATTRIBUTEVALUES xml tag
26 * <pre>
27 * <ASSETSET.GETATTRIBUTEVALUES NAME="assetsetname" ATTRIBUTE="attribname"
28 * [TYPENAME="assettypename"] LISTVARNAME="varname"
29 * [ORDERING="ascending|descending"]/>
30 * </pre>
31 *
32 * @author Mike Field
33 * @author Dolf Dijkstra
34 * @since July 15, 2008
35 */
36 public final class GetAttributeValues extends AbstractTagRunner {
37 // Default Constructor
38 public GetAttributeValues() {
39 super("ASSETSET.GETATTRIBUTEVALUES");
40 }
41
42 /**
43 * Sets name to the value of <code>s</code>
44 *
45 * @param s The name of the assetset to return
46 */
47 public void setName(String s) {
48 // validate first
49 if (s == null || s.length() == 0) {
50 throw new IllegalArgumentException("Invalid name string: " + s);
51 }
52 this.set("NAME", s);
53 }
54
55 /**
56 * Sets attribute to the value of <code>s</code>
57 *
58 * @param s The name of the attribute
59 */
60 public void setAttribute(String s) {
61 // validate first
62 if (s == null || s.length() == 0) {
63 throw new IllegalArgumentException("Invalid attribute string: " + s);
64 }
65 this.set("ATTRIBUTE", s);
66 }
67
68 /**
69 * Sets listvarname to the value of <code>s</code>
70 *
71 * @param s The name of the listvarname
72 */
73 public void setListvarname(String s) {
74 // validate first
75 if (s == null || s.length() == 0) {
76 throw new IllegalArgumentException("Invalid listvarname string: " + s);
77 }
78 this.set("LISTVARNAME", s);
79 }
80
81 /**
82 * Sets typename to the value of <code>s</code>
83 *
84 * @param s The attribute's typename
85 */
86 public void setTypename(String s) {
87 // validate first
88 if (s == null || s.length() == 0) {
89 throw new IllegalArgumentException("Invalid typename string: " + s);
90 }
91 this.set("TYPENAME", s);
92 }
93
94 /**
95 * Sets immediateonly to the value of <code>s</code>
96 *
97 * @param s The value of immediateonly: true or false
98 */
99 public void setImmediateonly(String s) {
100 // validate first
101 if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
102 throw new IllegalArgumentException("Invalid immediateonly string: " + s);
103 }
104 this.set("IMMEDIATEONLY", s);
105 }
106
107 /**
108 * Sets ordering to the value of <code>s</code>
109 *
110 * @param s The value of the ordering field: ascending or descending
111 */
112 public void setOrdering(String s) {
113 // validate first
114 if (s == null || s.length() == 0 || !s.equals("ascending") && !s.equals("descending")) {
115 throw new IllegalArgumentException("Invalid ordering string: " + s);
116 }
117 this.set("ORDERING", s);
118 }
119
120 /**
121 * @param ics Content Server context object
122 * @param id asset id
123 * @param deptype deptype
124 * @param locale locale string
125 * @param attr attribute name
126 * @param attrType attribute type
127 * @param ordering string value for attribute ordering
128 * @return IList with the attribute values.
129 */
130 public static IList getAttributeValues(ICS ics, AssetId id, String deptype, String locale, String attr,
131 String attrType, String ordering) {
132
133 // create asset set
134 SetAsset setAsset = new SetAsset();
135 final String assetSetName = "__AssetSet" + ics.genID(false);
136 setAsset.setName(assetSetName);
137 setAsset.setType(id.getType());
138 setAsset.setId(Long.toString(id.getId()));
139 if (deptype != null) {
140 setAsset.setDeptype(deptype);
141 }
142 if (locale != null) {
143 setAsset.setLocale(locale);
144 }
145 setAsset.execute(ics);
146
147 GetAttributeValues gav = new GetAttributeValues();
148 gav.setName(assetSetName);
149 gav.setAttribute(attr);
150 if (attrType != null) {
151 gav.setTypename(attrType);
152 }
153 if (ordering != null) {
154 gav.setOrdering(ordering);
155 }
156 String listname = ics.genID(true);
157 gav.setListvarname(listname);
158 gav.execute(ics);
159
160 IList result = ics.GetList(listname);
161 ics.RegisterList(listname, null);
162 return result;
163 }
164
165 }