1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.runtag.asset;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import COM.FutureTense.Interfaces.ICS;
23 import COM.FutureTense.Interfaces.IList;
24 import COM.FutureTense.Util.IterableIListWrapper;
25
26 import com.fatwire.assetapi.data.AssetId;
27 import com.fatwire.gst.foundation.IListUtils;
28 import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
29 import com.openmarket.xcelerate.asset.AssetIdImpl;
30
31
32
33
34
35
36
37
38
39
40
41 public class Children extends AbstractTagRunner {
42 public Children() {
43 super("ASSET.CHILDREN");
44 }
45
46 public void setName(String name) {
47 set("NAME", name);
48 }
49
50 public void setType(String type) {
51 set("TYPE", type);
52 }
53
54 public void setAssetId(String parentId) {
55 set("ASSETID", parentId);
56 }
57
58 public void setList(String list) {
59 set("LIST", list);
60 }
61
62 public void setCode(String code) {
63 set("CODE", code);
64 }
65
66 public void setObjectType(String otype) {
67 set("OBJECTTYPE", otype);
68 }
69
70 public void setObjectId(String oid) {
71 set("OBJECTID", oid);
72 }
73
74 public void setOrder(String order) {
75 set("ORDER", order);
76 }
77
78 @Override
79 protected void handleError(ICS ics) {
80 if (ics.GetErrno() == -111)
81 return;
82 super.handleError(ics);
83 }
84
85
86
87
88
89
90
91
92
93
94
95 public static AssetId getSingleAssociation(ICS ics, String c, String cid, String code) {
96 ics.RegisterList("spu-kids", null);
97 Children ac = new Children();
98 ac.setType(c);
99 ac.setAssetId(cid);
100 ac.setCode(code);
101 ac.setList("spu-kids");
102 ac.execute(ics);
103 IList spukids = ics.GetList("spu-kids");
104 ics.RegisterList("spu-kids", null);
105 if (spukids != null && spukids.hasData()) {
106 if (spukids.numRows() > 1) {
107 throw new IllegalStateException("Too many kids found associated to: " + c + ":" + cid
108 + " for association:" + code + ". expected 1 but got " + spukids.numRows());
109 }
110 spukids.moveTo(1);
111 return new AssetIdImpl(IListUtils.getStringValue(spukids, "otype"), IListUtils.getLongValue(spukids, "oid"));
112 } else {
113 throw new IllegalStateException("No kids found associated to: " + c + ":" + cid + " for association:"
114 + code + ". expected 1 but got none.");
115 }
116 }
117
118
119
120
121
122
123
124
125
126
127
128 public static AssetId getOptionalSingleAssociation(ICS ics, String c, String cid, String code) {
129 ics.RegisterList("spu-kids", null);
130 Children ac = new Children();
131 ac.setType(c);
132 ac.setAssetId(cid);
133 ac.setCode(code);
134 ac.setList("spu-kids");
135 ac.execute(ics);
136 IList spukids = ics.GetList("spu-kids");
137 ics.RegisterList("spu-kids", null);
138 if (spukids != null && spukids.hasData()) {
139 if (spukids.numRows() > 1) {
140 throw new IllegalStateException("Too many kids found associated to: " + c + ":" + cid
141 + " for association:" + code + ". expected 0 or 1 but got " + spukids.numRows());
142 }
143 spukids.moveTo(1);
144 return new AssetIdImpl(IListUtils.getStringValue(spukids, "otype"), IListUtils.getLongValue(spukids, "oid"));
145 } else {
146 return null;
147 }
148 }
149
150
151
152
153
154
155
156
157
158
159
160 public static List<AssetId> getOptionalMultivaluedAssociation(ICS ics, String c, String cid, String code) {
161 ics.RegisterList("spu-kids", null);
162 Children ac = new Children();
163 ac.setType(c);
164 ac.setAssetId(cid);
165 ac.setCode(code);
166 ac.setList("spu-kids");
167 ac.execute(ics);
168 IList spukids = ics.GetList("spu-kids");
169 ics.RegisterList("spu-kids", null);
170 List<AssetId> result = new ArrayList<AssetId>();
171 if (spukids != null && spukids.hasData()) {
172 for (IList row : new IterableIListWrapper(spukids)) {
173 result.add(new AssetIdImpl(IListUtils.getStringValue(row, "otype"), IListUtils.getLongValue(row, "oid")));
174
175 }
176 }
177 return result;
178 }
179
180
181
182
183
184
185
186
187
188
189
190 public static List<AssetId> getMultivaluedAssociation(ICS ics, String c, String cid, String code) {
191 List<AssetId> result = getOptionalMultivaluedAssociation(ics, c, cid, code);
192 if (result.size() == 0) {
193 throw new IllegalStateException("No kids found associated to: " + c + ":" + cid + " for association:"
194 + code + ". expected at least one but got none.");
195 }
196 return result;
197 }
198 }