1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.wra.navigation;
17
18 import java.util.Date;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import COM.FutureTense.Interfaces.ICS;
25
26 import com.fatwire.assetapi.data.AssetId;
27 import com.fatwire.assetapi.site.SiteInfo;
28 import com.fatwire.gst.foundation.controller.AssetIdWithSite;
29 import com.fatwire.gst.foundation.facade.assetapi.asset.TemplateAssetAccess;
30 import com.fatwire.gst.foundation.navigation.NavigationNode;
31 import com.fatwire.gst.foundation.navigation.NavigationService;
32 import com.fatwire.gst.foundation.wra.Alias;
33 import com.fatwire.gst.foundation.wra.AliasCoreFieldDao;
34 import com.fatwire.gst.foundation.wra.AssetApiAliasCoreFieldDao;
35 import com.fatwire.gst.foundation.wra.AssetApiWraCoreFieldDao;
36 import com.fatwire.gst.foundation.wra.WraCoreFieldDao;
37 import com.fatwire.mda.DimensionFilterInstance;
38 import com.openmarket.xcelerate.asset.AssetIdImpl;
39
40
41
42
43
44
45
46 public abstract class AbstractNavigationHelper {
47
48
49
50
51 protected final ICS ics;
52
53 protected abstract NavigationNode getSitePlan(final int depth, final AssetId pageId, final int level,
54 final DimensionFilterInstance dimensionFilter);
55
56 protected final TemplateAssetAccess assetTemplate;
57
58
59
60 protected final WraCoreFieldDao wraDao;
61
62
63
64 protected final AliasCoreFieldDao aliasDao;
65
66
67
68 protected static final Log LOG = LogFactory.getLog(AbstractNavigationHelper.class);
69
70
71
72
73 protected final Date assetEffectiveDate;
74
75
76
77
78
79 public static final String NAVBAR_NAME = "GSTNavName";
80
81
82
83
84 public static final String NAVBAR_LINK = "GSTNavLink";
85
86
87
88 public final String GST_ALIAS_TYPE = Alias.ALIAS_ASSET_TYPE_NAME;
89
90 public AbstractNavigationHelper(final ICS ics) {
91 this.ics = ics;
92 this.wraDao = new AssetApiWraCoreFieldDao(ics);
93
94 this.aliasDao = new AssetApiAliasCoreFieldDao(ics, wraDao);
95 this.assetEffectiveDate = null;
96 assetTemplate = new TemplateAssetAccess(ics);
97 }
98
99
100
101
102
103
104
105
106
107
108 public AbstractNavigationHelper(final ICS ics, TemplateAssetAccess assetTemplate, WraCoreFieldDao wraDao,
109 AliasCoreFieldDao aliasDao) {
110 this.ics = ics;
111 this.wraDao = wraDao;
112 this.aliasDao = aliasDao;
113 this.assetTemplate = assetTemplate;
114 this.assetEffectiveDate = null;
115 }
116
117
118
119
120
121 public NavigationNode getSitePlanByPage(final String name) {
122 return getSitePlanByPage(1, name);
123 }
124
125
126
127
128
129
130
131
132 public NavigationNode getSitePlanByPage(final int depth, final String name) {
133 final String sitename = ics.GetVar("site");
134 if (StringUtils.isBlank(sitename)) {
135 throw new IllegalStateException(
136 "site is not a ics variable. This function needs this variable to be avaible and contain the name of the site.");
137 }
138
139 return getSitePlanByPage(depth, name, sitename);
140 }
141
142
143
144
145
146
147
148
149
150 public NavigationNode getSitePlanByPage(final int depth, final String name, final DimensionFilterInstance dimensionFilter) {
151 final String sitename = ics.GetVar("site");
152 if (StringUtils.isBlank(sitename)) {
153 throw new IllegalStateException(
154 "site is not a ics variable. This function needs this variable to be aviable and contain the name of the site.");
155 }
156
157 return getSitePlanByPage(depth, name, sitename, dimensionFilter);
158 }
159
160
161
162
163
164
165
166
167
168 public NavigationNode getSitePlanByPage(final int depth, final String name, final String sitename) {
169 return getSitePlanByPage(depth, name, sitename, null);
170 }
171
172
173
174
175
176
177
178
179
180
181 public NavigationNode getSitePlanByPage(final int depth, final String name, final String sitename,
182 final DimensionFilterInstance dimensionFilter) {
183
184 final SiteInfo site = assetTemplate.readSiteInfo(sitename);
185 if (site == null) {
186 throw new RuntimeException("Site with name '" + sitename + "' not found.");
187 }
188 final AssetId pageid = assetTemplate.findByName(ics, "Page", name, site.getId());
189 if (pageid == null) {
190 return null;
191 }
192 return getSitePlan(depth, pageid, dimensionFilter);
193 }
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 public NavigationNode getSitePlan(final String pageid) {
212 return getSitePlan(new AssetIdImpl("Page", Long.parseLong(pageid)));
213 }
214
215
216
217
218
219
220
221 public NavigationNode getSitePlan(final AssetId pageid) {
222 return getSitePlan(-1, pageid, 0, null);
223 }
224
225
226
227
228
229
230
231
232 public NavigationNode getSitePlan(final int depth, final AssetId pageid) {
233 return getSitePlan(depth, pageid, 0, null);
234 }
235
236
237
238
239
240
241
242
243
244 public NavigationNode getSitePlan(final int depth, final AssetId pageid, final DimensionFilterInstance dimensionFilter) {
245 LOG.debug("Dimension filter " + dimensionFilter + " provided for site plan lookup");
246 return getSitePlan(depth, pageid, 0, dimensionFilter);
247 }
248
249
250
251
252
253
254
255
256
257
258 protected boolean isGstAlias(final AssetId id) {
259 return GST_ALIAS_TYPE.equals(id.getType());
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 public long findP(final String site_name, final AssetId wraAssetId) {
277 return wraDao.findP(new AssetIdWithSite(wraAssetId.getType(), wraAssetId.getId(), site_name));
278 }
279
280 }