1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.runtag.siteplan;
18
19 import COM.FutureTense.Interfaces.ICS;
20 import COM.FutureTense.Interfaces.IList;
21 import COM.FutureTense.Util.IterableIListWrapper;
22 import com.fatwire.assetapi.data.AssetId;
23 import com.openmarket.xcelerate.asset.AssetIdImpl;
24 import tools.gsf.facade.runtag.AbstractTagRunner;
25 import tools.gsf.facade.runtag.asset.AssetLoadById;
26 import tools.gsf.facade.runtag.asset.GetSiteNode;
27 import tools.gsf.facade.sql.IListUtils;
28 import tools.gsf.runtime.CSRuntimeException;
29
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42 public final class ListPages extends AbstractTagRunner {
43 public ListPages() {
44 super("SITEPLAN.LISTPAGES");
45 }
46
47 public void setName(String name) {
48 set("NAME", name);
49 }
50
51 public void setPlacedList(String placedPages) {
52 set("PLACEDLIST", placedPages);
53 }
54
55 public void setLevel(int level) {
56 set("LEVEL", Integer.toString(level));
57 }
58
59
60
61
62
63
64
65
66
67
68 public static List<AssetId> getChildPages(ICS ics, long p) {
69 final String LOADED_PAGE_NAME = "__thePage";
70 final String LOADED_SITE_PLAN_NODE = "__siteplan";
71 final String CURRENT_PAGE_NODE_ID = "__nodeId";
72 final String PLACED_LIST = "__placedList";
73
74 try {
75 AssetLoadById assetLoad = new AssetLoadById();
76 assetLoad.setAssetId(p);
77 assetLoad.setAssetType("Page");
78 assetLoad.setName(LOADED_PAGE_NAME);
79 assetLoad.execute(ics);
80 if (ics.GetErrno() < 0) {
81 throw new CSRuntimeException("Failed to load page identified by Page:" + p, ics.GetErrno());
82 }
83
84 GetSiteNode getSiteNode = new GetSiteNode();
85 getSiteNode.setName(LOADED_PAGE_NAME);
86 getSiteNode.setOutput(CURRENT_PAGE_NODE_ID);
87 getSiteNode.execute(ics);
88 if (ics.GetErrno() < 0) {
89 throw new CSRuntimeException("Could not get site node for page identified by Page:" + p, ics.GetErrno());
90 }
91
92 SitePlanLoad sitePlanLoad = new SitePlanLoad();
93 sitePlanLoad.setName(LOADED_SITE_PLAN_NODE);
94 sitePlanLoad.setNodeid(ics.GetVar(CURRENT_PAGE_NODE_ID));
95 sitePlanLoad.execute(ics);
96 if (ics.GetErrno() < 0) {
97 throw new CSRuntimeException("Could not load site plan tree for page identified by Page:" + p,
98 ics.GetErrno());
99 }
100
101 ListPages listPages = new ListPages();
102 listPages.setName(LOADED_SITE_PLAN_NODE);
103 listPages.setPlacedList(PLACED_LIST);
104 listPages.setLevel(1);
105 listPages.execute(ics);
106 if (ics.GetErrno() < 0) {
107 throw new CSRuntimeException("Could not get list child pages for Page:" + p, ics.GetErrno());
108 }
109
110
111 IList placedList = ics.GetList(PLACED_LIST);
112 if (ics.GetErrno() < 0 || placedList == null || !placedList.hasData()) {
113 ics.ClearErrno();
114 return Collections.emptyList();
115 }
116 List<AssetId> list = new ArrayList<AssetId>();
117 for (IList row : new IterableIListWrapper(placedList)) {
118 AssetId id = new AssetIdImpl(IListUtils.getStringValue(row, "AssetType"), IListUtils.getLongValue(row,
119 "Id"));
120 list.add(id);
121 }
122 return list;
123 } finally {
124 ics.SetObj(LOADED_PAGE_NAME, null);
125 ics.RemoveVar(CURRENT_PAGE_NODE_ID);
126 ics.SetObj(LOADED_SITE_PLAN_NODE, null);
127 ics.RegisterList(PLACED_LIST, null);
128 }
129 }
130 }