Si รจ verificato un errore nell'elaborarazione del modello.
The target variable of the assignment, "facetToProcess", was null or missing, but the "+=" operator needs to get its value before assigning to it.

----
Tip: If the target variable is known to be legally null or missing sometimes, instead of something like <#assign x += 1>, you could write <#if x??><#assign x += 1></#if> or <#assign x = (x!0) + 1>
----

----
FTL stack trace ("~" means nesting-related):
	- Failed at: #assign facetToProcess += {"values": ...  [in template "3144088#3144123#3189782" in function "processFacet" at line 835, column 4]
	- Reached through: x = processFacet(fp1)  [in template "3144088#3144123#3189782" in function "processFacets" at line 806, column 9]
	- Reached through: #assign-container  [in template "3144088#3144123#3189782" in function "processFacets" at line 804, column 5]
	- Reached through: processedFacets = processFacets(facets)  [in template "3144088#3144123#3189782" in macro "writeItems" at line 431, column 9]
	- Reached through: #assign-container  [in template "3144088#3144123#3189782" in macro "writeItems" at line 427, column 5]
	- Reached through: @writeItems  [in template "3144088#3144123#3189782" at line 396, column 13]
----
1<#import "_TEMPLATE_CONTEXT_/3144088/3149724/23609/3151242" as d40> 
2 
3<#compress> 
4<#setting url_escaping_charset="UTF-8"> 
5 
6<#assign 
7    SuggestoMarketspaceAPI = serviceLocator.findService("eu.suggesto.marketspace.service.SmkspDataLocalService") 
8    SuggestoRecommenderServiceAPI = serviceLocator.findService("eu.suggesto.servicecs.service.SuggestoRecommenderLocalService") 
9    SuggestoCSServiceAPI = serviceLocator.findService("eu.suggesto.servicecs.service.SuggestoCSLocalService") 
10    d40Service = serviceLocator.findService("eu.suggesto.d40.builder.d40.service.TourismItemLocalService") 
11    JALS = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") 
12     
13    ddmStructureKey = "*" 
14    structureKey1 = "1365076" 
15    structureKey2 = "1332941" 
16    structureKey3 = "1332945" 
17    structureKey4 = "1332946" 
18    structureKey5 = "1332947" 
19     
20    serviceName = "0:esvisitsicilia" 
21    serverName = "" 
22    srvGroupId = groupId?string 
23    defLng = "it_IT" 
24    numPag = 1 
25    numItems = 10 
26    jsonParams = d40.createObject("") 
27     
28    szJsonParams = result.getNamespacedParameters().getString("jsonParams") 
29/> 
30 
31<#assign rndSort> 
32
33    _script: { 
34        script: "2005000", 
35        type: "number", 
36        params: {}, 
37        order: "asc" 
38
39
40</#assign> 
41 
42<#if szJsonParams?has_content> 
43    <#assign jsonParams = d40.createObject(szJsonParams)> 
44</#if> 
45 
46<#if jsonParams.getString("pag")?has_content> 
47    <#assign numPag = jsonParams.getString("pag")?number> 
48</#if> 
49 
50<#if jsonParams.getString("num")?has_content> 
51    <#assign numItems = jsonParams.getString("num")?number> 
52</#if> 
53 
54<#assign 
55    query = jsonParams.getString("qry") 
56    structureKey = jsonParams.getString("structureKey") 
57    uid = jsonParams.getString("uid") 
58    kw = jsonParams.getString("kw", "*") 
59    p1 = jsonParams.getString("p1", "*") 
60    p2 = jsonParams.getString("p2", "*") 
61    p3 = jsonParams.getString("p3", "*") 
62    p4 = jsonParams.getString("p4", "*") 
63    p5 = jsonParams.getString("p5", "*") 
64    p6 = jsonParams.getString("p6", "*") 
65    p7 = jsonParams.getString("p7", "*") 
66    p8 = jsonParams.getString("p8", "*") 
67    p9 = jsonParams.getString("p9", "*") 
68    p10 = jsonParams.getString("p10", "*") 
69    d1 = jsonParams.getString("d1", "*") 
70    d2 = jsonParams.getString("d2", "*") 
71    queryAndOperatorP1 = jsonParams.getString("queryAndOperatorP1", "") 
72    queryAndOperatorP2 = jsonParams.getString("queryAndOperatorP2", "") 
73    queryAndOperatorP3 = jsonParams.getString("queryAndOperatorP3", "") 
74    queryAndOperatorP4 = jsonParams.getString("queryAndOperatorP4", "") 
75    queryAndOperatorC1 = jsonParams.getString("queryAndOperatorC1", "") 
76    queryAndOperator0 = jsonParams.getString("queryAndOperator0", "") 
77    queryAndOperator1 = jsonParams.getString("queryAndOperator1", "") 
78    orderByColumn1 = jsonParams.getString("orderByColumn1", "") 
79    orderByColumn2 = jsonParams.getString("orderByColumn2", "") 
80    orderByType1 = jsonParams.getString("orderByType1", "") 
81    orderByType2 = jsonParams.getString("orderByType2", "") 
82    f0 = jsonParams.getString("f0", "") 
83    f1 = jsonParams.getString("f1", "") 
84    c1 = jsonParams.getString("c1", "") 
85    sortOrder = jsonParams.getString("so", "") 
86    scopeIds = jsonParams.getString("scopeIds", "") 
87    mode = jsonParams.getString("mode", "") 
88    pt = jsonParams.getString("pt") 
89    ptflt = jsonParams.getString("ptflt") 
90    dist = jsonParams.getString("d", "1") 
91    lng = jsonParams.getString("lng", locale.toString()) 
92    fields = jsonParams.getString("flds", "*") 
93    varjs = jsonParams.getString("varjs", "isct") 
94    skipItems = (numPag-1) * numItems 
95    locLng = localeUtil.fromLanguageId(lng) 
96    locDef = localeUtil.fromLanguageId("it_IT") 
97    today = dateUtil.parseDate(.now?string("dd")+ "/" + .now?string("MM") + "/" + .now?string("yyyy"), locDef) 
98    szExpDate = .now?string("yyyy") + .now?string("MM") + .now?string("dd") + .now?string("hh") + .now?string("mm") + .now?string("ss") 
99    szToday = .now?string("yyyy") + "-" + .now?string("MM") + "-" + .now?string("dd") 
100    jsort = [] 
101/> 
102 
103<#if orderByType1 != "ASC" && orderByType1 != "DESC">  
104    <#assign orderByType1 ="DESC"> 
105</#if> 
106 
107<#if orderByColumn1 == "title"> 
108    <#assign orderByColumn1 = "localized_title_it_IT_sortable"> 
109</#if> 
110 
111<#if orderByColumn1 == "modifiedDate"> 
112    <#assign orderByColumn1 = "modified_sortable"> 
113</#if> 
114 
115<#if structureKey == "1332933"> 
116    <#assign 
117        orderByColumn1="ddm__keyword__1332934__dataFine" 
118        orderByType1 = "ASC" 
119    /> 
120</#if> 
121 
122<#if orderByColumn1?starts_with("ddm__keyword")> 
123    <#assign orderByColumn1 += "_it_IT_String_sortable"> 
124</#if> 
125 
126<#if orderByColumn2 == "title"> 
127    <#assign orderByColumn2 = "localized_title_it_IT_sortable"> 
128</#if> 
129 
130<#if orderByColumn2 == "modifiedDate"> 
131    <#assign orderByColumn2 = "modified_sortable"> 
132</#if> 
133 
134<#if orderByColumn2?starts_with("ddm__keyword")>  
135    <#assign orderByColumn2 += "_it_IT_String_sortable"> 
136</#if> 
137 
138<#if query?has_content && query == "global"> 
139    <#assign 
140        querySlr1 = "head:true AND status:0 AND ddmStructureKey:${structureKey1} AND expirationDate:[${szExpDate} TO *]" 
141        querySlr2 = "head:true AND status:0 AND ddmStructureKey:${structureKey2} AND expirationDate:[${szExpDate} TO *]" 
142        querySlr3 = "head:true AND status:0 AND ddmStructureKey:${structureKey3} AND expirationDate:[${szExpDate} TO *]" 
143        querySlr4 = "head:true AND status:0 AND ddmStructureKey:${structureKey4} AND expirationDate:[${szExpDate} TO *]" 
144        querySlr5 = "head:true AND status:0 AND ddmStructureKey:${structureKey5} AND expirationDate:[${szExpDate} TO *]" 
145    /> 
146     
147    <#if structureKey == "1332933" && !d1?has_content> 
148        <#assign d1 = szToday> 
149    </#if> 
150     
151    <#if d1?has_content && structureKey?has_content && structureKey == "1332933"> 
152        <#assign querySlr5 = querySlr5 + " AND ddm__keyword__1332934__dataFine_it_IT:[${d1} TO *]"> 
153         
154        <#if d2?has_content && structureKey?has_content && structureKey == "1332933"> 
155            <#assign querySlr5 = querySlr5 + " AND ddm__keyword__1332934__dataInizio_it_IT:[* TO ${d2}]"> 
156        </#if> 
157    </#if> 
158 
159    <#assign querySlrFull = "head:true AND status:0 AND (ddmStructureKey:(${structureKey1} OR ${structureKey2} OR ${structureKey3} OR ${structureKey4} OR ${structureKey5})) AND expirationDate:[${szExpDate} TO *]"> 
160     
161    <#if kw?has_content> 
162        <#assign 
163            querySlr1 += " AND content:${kw}" 
164            querySlr2 += " AND content:${kw}" 
165            querySlr3 += " AND content:${kw}" 
166            querySlr4 += " AND content:${kw}" 
167            querySlr5 += " AND content:${kw}" 
168            querySlrFull += " AND content:${kw}" 
169        /> 
170    </#if> 
171<#else> 
172    <#assign querySlr = "head:true AND status:0 AND expirationDate:[${szExpDate} TO *]"> 
173     
174    <#if structureKey?has_content>  
175        <#assign querySlr += " AND ddmStructureKey:${structureKey}"> 
176         
177        <#if scopeIds?has_content> 
178            <#assign querySlr += " AND groupId:${scopeIds}"> 
179        </#if> 
180         
181        <@setFilterParam param=f0 operator=queryAndOperator0 cats=f0Cats /> 
182         
183        <@setFilterParam param=f1 operator=queryAndOperator1 cats=f1Cats /> 
184         
185        <@setFilterParam param=c1 operator=queryAndOperatorC1 cats=c1Cats /> 
186    <#else> 
187        <#if scopeIds?has_content> 
188            <#assign querySlr = "head:true AND status:0 AND groupId:${scopeIds} AND ddmStructureKey:${ddmStructureKey} AND expirationDate:[${szExpDate} TO *]"> 
189             
190            <#if scopeIds?has_content> 
191                <#assign querySlr += " AND groupId:${scopeIds}"> 
192            </#if> 
193         
194            <@setFilterParam param=f0 operator=queryAndOperator0 cats=f0Cats /> 
195             
196            <@setFilterParam param=f1 operator=queryAndOperator1 cats=f1Cats /> 
197             
198            <@setFilterParam param=c1 operator=queryAndOperatorC1 cats=c1Cats /> 
199        </#if> 
200    </#if> 
201     
202    <#if uid?has_content> 
203        <#assign querySlr += " AND articleId:${uid}"> 
204    </#if> 
205     
206    <#if kw?has_content> 
207        <#assign querySlr += " AND content:${kw}"> 
208    </#if> 
209</#if> 
210 
211<#if orderByColumn1?has_content> 
212    <#assign jsort += [{orderByColumn1, orderByType1}]> 
213</#if> 
214 
215<#if orderByColumn2?has_content> 
216    <#assign jsort += [{orderByColumn2, orderByType2}]> 
217</#if> 
218 
219<#if sortOrder != "random"> 
220    <#assign sortOrder = d40.printPlain(jsort)> 
221<#else> 
222    <#assign sortOrder = "{'random':{}}">      
223</#if> 
224 
225<#if kw?trim?has_content> 
226    <#assign sortOrder = "">   
227<#else> 
228    <#assign kw = "*"> 
229</#if> 
230 
231<#if !p1?has_content> 
232    <#assign p1 = "*"> 
233</#if> 
234<#if !p2?has_content> 
235    <#assign p2 = "*"> 
236</#if> 
237<#if !p3?has_content> 
238    <#assign p3 = "*"> 
239</#if> 
240<#if !p4?has_content> 
241    <#assign p4 = "*"> 
242</#if> 
243<#if !p5?has_content> 
244    <#assign p5 = "*"> 
245</#if> 
246 
247<#if structureKey == "1332933" && !d1?has_content> 
248    <#assign d1 = szToday> 
249</#if> 
250 
251<#if structureKey == "1332933" && !d1?has_content> 
252    <#assign d1 = szToday> 
253</#if> 
254 
255<#if d1?has_content && structureKey?has_content && structureKey == "1332933"> 
256    <#assign querySlr += " AND ddm__keyword__1332934__dataFine_it_IT:[${d1} TO *]"> 
257     
258    <#if d2?has_content && structureKey?has_content && structureKey == "1332933"> 
259        <#assign querySlr += " AND ddm__keyword__1332934__dataInizio_it_IT:[* TO ${d2}]"> 
260    </#if> 
261</#if> 
262 
263<#if query?has_content && query == "global"> 
264    <#assign 
265        queryEs1 = buildQueryEs(querySlr1) 
266        queryEs2 = buildQueryEs(querySlr2) 
267        queryEs3 = buildQueryEs(querySlr3) 
268        queryEs4 = buildQueryEs(querySlr4) 
269        queryEs5 = buildQueryEs(querySlr5) 
270        queryEsFull = buildQueryEs(querySlrFull) 
271         
272        resultQry1 = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEs1, sortOrder, skipItems, numItems) 
273        resultQry2 = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEs2, sortOrder, skipItems, numItems) 
274        resultQry3 = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEs3, sortOrder, skipItems, numItems) 
275        resultQry4 = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEs4, sortOrder, skipItems, numItems) 
276        resultQry5 = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEs5, sortOrder, skipItems, numItems) 
277        resultQryFull = SuggestoRecommenderServiceAPI.search("0", serviceName,"", queryEsFull, sortOrder, skipItems, numItems) 
278    /> 
279         
280    <#if !resultQryFull?has_content || resultQryFull.getJSONObject("data").getJSONObject("response").getString("numFound")?number == 0> 
281
282            "metadata": { 
283                "numFound": 0, 
284                "start": 0, 
285                "queryEsFull": "${d40.getJsonString(queryEsFull)}", 
286                "sortOrder": "${d40.getJsonString(sortOrder)}" 
287            }, 
288            "docs": [], 
289            "service": "${serviceName}" 
290        }   
291    <#else> 
292        <#assign 
293            numFound = resultQryFull.getJSONObject("data").getJSONObject("response").getString("numFound")?number 
294            start = resultQryFull.getJSONObject("data").getJSONObject("response").getString("start")?number 
295        /> 
296         
297        <#if (numFound > 0)> 
298            <#assign 
299                start = resultQryFull.getJSONObject("data").getJSONObject("response").getString("start") 
300                items1 = resultQry1.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
301                items2 = resultQry2.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
302                items3 = resultQry3.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
303                items4 = resultQry4.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
304                items5 = resultQry5.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
305                facets = resultQryFull.getJSONObject("data").getJSONObject("aggregations") 
306                processedFacets = processFacets(facets) 
307                first = true 
308            /> 
309             
310
311                "metadata": { 
312                    "numFound": ${numFound}, 
313                    "start": ${start}, 
314                    "queryEsFull": "${d40.getJsonString(queryEsFull)}", 
315                    "sortOrder": "${d40.getJsonString(sortOrder)}", 
316                    "c1": "${c1}", 
317                    "orderByColumn1": "${orderByColumn1}", 
318                    "orderByType1": "${orderByType1}" 
319                }, 
320                "docs": [ 
321                    <#list 0..items1.length()-1 as i> 
322                        <#if items1.getJSONObject(i)?has_content> 
323                            <#assign doc = items1.getJSONObject(i)> 
324                             
325                            <@jsonoutput /> 
326                        </#if>   
327                    </#list> 
328                     
329                    <#list 0..items2.length()-1 as i> 
330                        <#if items2.getJSONObject(i)?has_content> 
331                            <#assign doc = items2.getJSONObject(i)> 
332                             
333                            <@jsonoutput /> 
334                        </#if>   
335                    </#list> 
336                     
337                    <#list 0..items3.length()-1 as i> 
338                        <#if items3.getJSONObject(i)?has_content> 
339                            <#assign doc = items3.getJSONObject(i)> 
340                             
341                            <@jsonoutput /> 
342                        </#if>   
343                    </#list> 
344                     
345                    <#list 0..items4.length()-1 as i> 
346                        <#if items4.getJSONObject(i)?has_content> 
347                            <#assign doc = items4.getJSONObject(i)> 
348                             
349                            <@jsonoutput /> 
350                        </#if>   
351                    </#list> 
352                     
353                    <#list 0..items5.length()-1 as i> 
354                        <#if items5.getJSONObject(i)?has_content> 
355                            <#assign doc = items5.getJSONObject(i)> 
356                             
357                            <@jsonoutput /> 
358                        </#if>   
359                    </#list> 
360                ], 
361                "facetedValues": ${processedFacets.toString()} 
362
363        <#else> 
364
365                "metadata": { 
366                    "numFound": ${numFound} 
367                }, 
368                "query": "${querySlrFull}" 
369
370        </#if> 
371    </#if> 
372<#else> 
373    <#assign 
374        queryEs = buildQueryEs(querySlr) 
375        resultQry = SuggestoRecommenderServiceAPI.search("0", serviceName, "", queryEs, sortOrder, skipItems, numItems) 
376    /> 
377 
378    <#if !resultQry?has_content> 
379
380            "metadata":{ 
381                "numFound": 0, 
382                "start": 0 
383            }, 
384            "docs": [], 
385            "service": "${serviceName}", 
386            "queryEs": "${d40.getJsonString(queryEs)}", 
387            "sortOrder2": "${d40.getJsonString(sortOrder)}" 
388
389    <#else> 
390        <#assign 
391            numFound = resultQry.getJSONObject("data").getJSONObject("response").getString("numFound")?number 
392            start = resultQry.getJSONObject("data").getJSONObject("response").getString("start")?number 
393        /> 
394 
395        <#if (numFound > 0) && (start < numFound)> 
396            <@writeItems/> 
397        <#else>   
398
399                "metadata": { 
400                    "numFound": ${numFound}, 
401                    "start": ${start} 
402                }, 
403                "docs": [], 
404                "queryEs": "${d40.getJsonString(queryEs)}" 
405
406        </#if>   
407    </#if>    
408</#if> 
409 
410<#macro setFilterParam param operator cats> 
411    <#if param?has_content> 
412        <#if operator == "true"> 
413            <#assign 
414                cats = d40.getAndOrParam(param, "AND", "") 
415                querySlr += " AND assetCategoryIds:(" + cats + ")" 
416            /> 
417        <#else> 
418            <#assign 
419                cats = d40.getAndOrParam(param, "OR", "") 
420                querySlr += " AND assetCategoryIds:(" + cats + ")" 
421            /> 
422        </#if> 
423    </#if> 
424</#macro> 
425     
426<#macro writeItems> 
427    <#assign 
428        start = resultQry.getJSONObject("data").getJSONObject("response").getString("start") 
429        items = resultQry.getJSONObject("data").getJSONObject("response").getJSONArray("docs") 
430        facets = resultQry.getJSONObject("data").getJSONObject("aggregations") 
431        processedFacets = processFacets(facets) 
432    /> 
433 
434
435        "metadata": { 
436            "numFound": ${numFound}, 
437            "start": ${start}, 
438            "c1": "${c1}", 
439            "orderByColumn1": "${orderByColumn1}", 
440            "orderByType1": "${orderByType1}", 
441            "queryEs": "${d40.getJsonString(queryEs)}", 
442            "sortOrder": "${d40.getJsonString(sortOrder)}" 
443        },  
444        "docs": [ 
445            <#list 0..items.length()-1 as i> 
446                <#assign doc = items.getJSONObject(i)> 
447                 
448                <@jsonoutput /> 
449            </#list> 
450        ], 
451        "facetedValues": ${processedFacets}  
452
453</#macro> 
454 
455<#macro jsonoutput> 
456    <#assign 
457        articleId = getLngStringFromJsonObject(doc, "articleId", lng, defLng, "") 
458        articleGroupId = getLngStringFromJsonObject(doc, "groupId", lng, defLng, "")?number 
459        article = d40Service.getByLng(articleGroupId, "", articleId, lng) 
460    /> 
461     
462    <#if article.getBoolean("success")> 
463        <#assign contentJSON = article.getJSONObject("data").getJSONObject("contentJSON")> 
464         
465        <#if groupId == articleGroupId?number> 
466            <#assign viewUrl = d40.mkspAPI.getArticleUrl(articleGroupId, "", articleId, locLng, locDef, "/det")> 
467        <#else> 
468            <#assign viewUrl = d40.mkspAPI.getArticleUrl(groupId, "", articleGroupId, articleId, locLng, locDef, "/det")> 
469        </#if> 
470         
471        <#assign 
472            contentJSON += {"viewUrl", viewUrl} 
473            contentJSON += {"articleGroupIdViewUrl", articleGroupId} 
474            contentJSON += {"articleIdViewUrl", articleId} 
475            contentJSON += {"locale", locLng.toString()} 
476            contentJSON += {"geoRef", d40.replaceStringWithGeoRef(contentJSON, "geoRef")} 
477        /> 
478       
479        <#if contentJSON.getString("coordinateTestuali")?has_content> 
480            <#assign contentJSON += d40.fromTestualiToGeoRef(contentJSON)> 
481        </#if> 
482 
483        <#if contentJSON.getString("previewPicture")?has_content> 
484            <#assign contentJSON += {"previewPicture", d40.generateImgUrl(contentJSON.getString("previewPicture"))}> 
485        </#if> 
486         
487        <#assign 
488            contentJSON += d40.replaceStringWithImagesArray(contentJSON, "pictures") 
489            groupedCategories = d40.mkspAPI.getGroupedArticleCategories(articleGroupId, articleId, locLng, locDef) 
490        /> 
491         
492        <#if groupedCategories?has_content> 
493            <#assign contentJSON += {"groupedCategories", groupedCategories}> 
494        </#if>  
495         
496        ${article.getJSONObject("data").toString()}, 
497    <#else> 
498
499            "articleId": "${articleId}, 
500            "status": "notfound" 
501
502    </#if> 
503</#macro>  
504 
505<#function buildQueryEs varName> 
506    <#assign rtnQuery> 
507
508     	"query": { 
509     		"bool": { 
510     			"must": [ 
511
512         				"query_string": { 
513         					"query": "${d40.getJsonString(varName)}" 
514
515     				}, 
516
517     					"query_string": { 
518     						"query": "assetCategoryIds:${p1}" 
519
520     				}, 
521
522     					"query_string": { 
523     						"query": "assetCategoryIds:${p2}" 
524
525     				}, 
526
527     					"query_string": { 
528     						"query": "assetCategoryIds:${p3}" 
529
530     				}, 
531
532     					"query_string": { 
533     						"query": "assetCategoryIds:${p4}" 
534
535     				}, 
536
537     					"query_string": { 
538     						"query": "assetCategoryIds:${p5}" 
539
540
541
542
543     	}, 
544        "_source": ["articleId", "groupId"],  
545        "aggs": { 
546     		"p1": { 
547     			"terms": { 
548     				"field": "assetCategoryIds", 
549     				"size": 200 
550
551     		}, 
552     		"p2": { 
553     			"terms": { 
554     				"field": "assetCategoryIds", 
555     				"size": 200 
556
557     		}, 
558    	    "p3": { 
559     			"terms": { 
560     				"field": "assetCategoryIds", 
561     				"size": 200 
562
563     		}, 
564    	    "p4": { 
565     			"terms": { 
566     				"field": "assetCategoryIds", 
567     				"size": 200 
568
569     		}, 
570    	    "p5": { 
571     			"terms": { 
572     				"field": "assetCategoryIds", 
573     				"size": 200 
574
575
576
577
578    </#assign> 
579     
580    <#return rtnQuery> 
581</#function> 
582 
583<#function resolveItems contentJSON nodeName> 
584    <#if contentJSON.getString(nodeName)?has_content && !contentJSON.getJSONArray(nodeName)?has_content> 
585        <#assign 
586            node = contentJSON.getString(nodeName) 
587            jnode = d40.createObject(node) 
588            stageGroupId = jnode.getString("groupId") 
589            stxArray = [] 
590        /> 
591         
592        <#if stageGroupId?has_content> 
593            <#assign 
594                className = jnode.getString("className") 
595                classPK = jnode.getString("classPK") 
596                linkedArticle = JALS.getLatestArticle(classPK?number?long) 
597                stageArticleId = linkedArticle.getArticleId() 
598                stageDocument = d40Service.getByLng(stageGroupId?number, "", stageArticleId, lng)!"" 
599            /> 
600             
601            <#if stageDocument?has_content> 
602                <#assign 
603                    v = cleanLiferayItem(stageDocument.getJSONObject("data")) 
604                    stageDocumentCJson = stageDocument.getJSONObject("data").getJSONObject("contentJSON") 
605                    z = resolveItem(stageDocumentCJson, "beacon") 
606                    stageDocumentCJson += d40.replaceStringWithJSONObject(stageDocumentCJson, "geoRef") 
607                    stageDocumentCJson += {"immagineLista", d40.generateImgUrl(stageDocumentCJson.getString("immagineLista"))} 
608                    stageDocumentCJson += {"map", d40.generateImgUrl(stageDocumentCJson.getString("map"))} 
609                    stageDocumentCJson += d40.replaceObjectWithArray(stageDocumentCJson, "infoItem") 
610                    infoItems = stageDocumentCJson.getJSONArray("infoItem") 
611                /> 
612                 
613                <#list 0..infoItems.length()-1 as i> 
614                    <#assign 
615                        infoItem = infoItems.getJSONObject(i) 
616                        infoItem += {"infoItemSpeech", d40.generateImgUrl(infoItem.getString("infoItemSpeech"))} 
617                        infoItem += {"infoItemPreviewPicture", d40.generateImgUrl(infoItem.getString("infoItemPreviewPicture"))} 
618                        infoItem += {"infoItemMainPicture", d40.generateImgUrl(infoItem.getString("infoItemMainPicture"))} 
619                        infoItem += d40.replaceStringWithImagesArray(infoItem, "infoItemMediaItem") 
620                    /> 
621                </#list> 
622                 
623                <#assign stxArray += [stageDocument.getJSONObject("data")]> 
624            </#if> 
625        </#if> 
626         
627        <#assign contentJSON += {nodeName + "Obj", stxArray}> 
628    <#else> 
629        <#if contentJSON.getJSONArray(nodeName)?has_content> 
630            <#assign 
631                stages = contentJSON.getJSONArray(nodeName) 
632                stxArray = [] 
633            /> 
634             
635            <#list 0..stages.length()-1 as i> 
636                <#assign node = stages.getString(i)> 
637                 
638                <#if node?has_content> 
639                    <#assign 
640                        jnode = d40.createObject(node) 
641                        stageGroupId = groupId 
642                    /> 
643                     
644                    <#if jnode.getString("groupId")?has_content> 
645                        <#assign stageGroupId = jnode.getString("groupId")> 
646                    </#if> 
647                     
648                    <#assign 
649                        className = jnode.getString("className") 
650                        classPK = jnode.getString("classPK") 
651                        linkedArticle = JALS.getLatestArticle(classPK?number?long) 
652                        stageArticleId = linkedArticle.getArticleId() 
653                        stageDocument = d40Service.getByLng(stageGroupId?number, "", stageArticleId, lng)!"" 
654                        x = cleanLiferayItem(stageDocument.getJSONObject("data")) 
655                        stageDocumentCJson = stageDocument.getJSONObject("data").getJSONObject("contentJSON") 
656                        stageDocumentCJson += d40.replaceStringWithJSONObject(stageDocumentCJson, "geoRef") 
657                        z = resolveItem(stageDocumentCJson, "beacon") 
658                        stageDocumentCJson += {"immagineLista", d40.generateImgUrl(stageDocumentCJson.getString("immagineLista"))} 
659                        stageDocumentCJson += {"map", d40.generateImgUrl(stageDocumentCJson.getString("map"))} 
660                        stageDocumentCJson += d40.replaceObjectWithArray(stageDocumentCJson, "infoItem") 
661                        infoItems = stageDocumentCJson.getJSONArray("infoItem") 
662                    /> 
663                     
664                    <#list 0..infoItems.length()-1 as i> 
665                        <#assign 
666                            infoItem += {"infoItemSpeech", d40.generateImgUrl(infoItems.getJSONObject(i).getString("infoItemSpeech"))} 
667                            infoItem += {"infoItemPreviewPicture", d40.generateImgUrl(infoItem.getString("infoItemPreviewPicture"))} 
668                            infoItem += {"infoItemMainPicture", d40.generateImgUrl(infoItem.getString("infoItemMainPicture"))} 
669                            infoItem += d40.replaceStringWithImagesArray(infoItem, "infoItemMediaItem") 
670                        /> 
671                    </#list> 
672                     
673                    <#assign stxArray += [stageDocument.getJSONObject("data")]> 
674                </#if> 
675            </#list> 
676             
677            <#assign contentJSON += {nodeName + "Obj", stxArray}>  
678        </#if> 
679    </#if> 
680     
681    <#return contentJSON> 
682</#function> 
683 
684<#function resolveItem contentJSON nodeName> 
685    <#assign itemDocumentCJson = d40.createObject("")> 
686     
687    <#if contentJSON.getString(nodeName)?has_content> 
688        <#assign 
689            node = contentJSON.getString(nodeName) 
690            jnode = d40.createObject(node) 
691            itemGroupId = jnode.getString("groupId") 
692            className = jnode.getString("className") 
693            classPK = jnode.getString("classPK") 
694            linkedArticle = JALS.getLatestArticle(classPK?number?long) 
695            itemArticleId = linkedArticle.getArticleId() 
696            itemDocument = d40Service.getByLng(itemGroupId?number, "", itemArticleId, lng)!"" 
697        /> 
698         
699        <#if itemDocument?has_content && itemDocument.getJSONObject("data")?has_content> 
700            <#assign 
701                objItemDocument = itemDocument.getJSONObject("data").getJSONObject("contentJSON") 
702                itemDocumentCJson += d40.replaceStringWithJSONObject(objItemDocument, "geoRef") 
703            /> 
704        </#if> 
705    </#if> 
706     
707    <#assign contentJSON += {nodeName + "Obj", itemDocumentCJson}> 
708     
709    <#return contentJSON> 
710</#function> 
711 
712<#function getLngStringFromJsonObject jsonObj fieldName lng defLng default> 
713    <#assign 
714        found = false 
715        result = getLngStringFromJsonObjectInternal(jsonObj, fieldName, lng, defLng) 
716    /> 
717     
718    <#if result == "notFound"> 
719        <#assign result = getLngStringFromJsonObjectInternal(jsonObj, fieldName, lng?keep_before("_"), defLng?keep_before("_"))> 
720         
721        <#if result == "notFound"> 
722            <#assign result = default> 
723        <#else> 
724            <#assign found = true> 
725        </#if> 
726    <#else> 
727        <#assign found = true> 
728    </#if> 
729     
730    <#if !found> 
731        <#assign result = default> 
732    </#if> 
733     
734    <#return d40.getJsonString(result)> 
735</#function> 
736 
737<#function getLngStringFromJsonObjectInternal jsonObj fieldName lng defLng> 
738    <#assign found = false> 
739     
740    <#if jsonObj.getJSONArray(fieldName + "_" + lng)??> 
741        <#assign 
742            retObj = jsonObj.getJSONArray(fieldName + "_" + lng) 
743            found = true 
744        /> 
745    </#if> 
746     
747    <#if !found> 
748        <#if jsonObj.getJSONArray(fieldName + "_" + defLng)??> 
749            <#assign 
750                retObj = jsonObj.getJSONArray(fieldName + "_" + defLng) 
751                found = true 
752            /> 
753        </#if> 
754    </#if> 
755     
756    <#if !found> 
757        <#if jsonObj.getJSONArray(fieldName)??> 
758            <#assign 
759                retObj = jsonObj.getJSONArray(fieldName) 
760                found = true 
761            /> 
762        </#if> 
763    </#if> 
764     
765    <#if found> 
766        <#assign result = retObj.getString(0)> 
767    </#if> 
768     
769    <#if !found> 
770        <#if jsonObj.getString(fieldName + "_" + lng)?has_content> 
771            <#assign 
772                result = jsonObj.getString(fieldName + "_" + lng) 
773                found = true 
774            /> 
775        </#if> 
776    </#if> 
777     
778    <#if !found> 
779        <#if jsonObj.getString(fieldName + "_" + defLng)?has_content> 
780            <#assign 
781                result = jsonObj.getString(fieldName + "_" + defLng) 
782                found = true 
783            /> 
784        </#if> 
785    </#if> 
786     
787    <#if !found> 
788        <#if jsonObj.getString(fieldName)?has_content> 
789            <#assign 
790                result = jsonObj.getString(fieldName) 
791                found = true 
792            /> 
793        </#if> 
794    </#if> 
795     
796    <#if !found> 
797        <#return "notFound"> 
798    </#if> 
799     
800    <#return result> 
801</#function> 
802 
803<#function processFacets facetsToProcess> 
804    <#assign 
805        fp1 = facetsToProcess.getJSONObject("p1") 
806        x = processFacet(fp1) 
807        fp2 = facetsToProcess.getJSONObject("p2") 
808        x = processFacet(fp2) 
809        fp3 = facetsToProcess.getJSONObject("p3") 
810        x = processFacet(fp3) 
811        fp4 = facetsToProcess.getJSONObject("p4") 
812        x = processFacet(fp4) 
813    /> 
814     
815    <#return facetsToProcess> 
816</#function> 
817   
818<#function processFacet facetToProcess> 
819    <#assign 
820        buckets = facetToProcess.getJSONArray("buckets") 
821        fpValues = {} 
822    /> 
823     
824    <#list 0..buckets.length()-1 as i> 
825        <#if buckets.getJSONObject(i)?has_content> 
826            <#assign 
827                bck = buckets.getJSONObject(i) 
828                keyBck = bck.getString("key") 
829                keyCount = bck.getLong("doc_count") 
830                fpValues += {keyBck, keyCount?string} 
831            /> 
832        </#if> 
833   </#list> 
834    
835   <#assign facetToProcess += {"values", fpValues}> 
836    
837   <#return facetToProcess> 
838</#function> 
839 
840</#compress>