-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCallSolrClientFactoryServer.js
71 lines (58 loc) · 2.53 KB
/
CallSolrClientFactoryServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function (request, response, ctx, collection, solrServer, solrClientFactory) {
// add your logic here
var SolrQuery = org.apache.solr.client.solrj.SolrQuery;
var ldapId = request.getFirstParam("ldapid");
//ldapId = 't894727';
logger.info("benjamin ldapid " + ldapId);
logger.info("benjamin " + request.getClass().getName());
var filterList = [];
if( ldapId ){
logger.info("benjamin starting");
try {
aSolrServer = solrClientFactory.getSolrServer("MAIN_UserProfiles");
logger.info("benjamin got server");
var q = new SolrQuery();
q.setQuery("ldapid_s:" + ldapId);
q.setFields("id,ldapid_s,rolelist_s,sitelist_s");
q.setRows(1);
var resp = aSolrServer.query(q);
logger.info("benjamin got " + resp.toString());
var docList = resp.getResults();
logger.info("benjamin doclist type " + docList.getClass().getName());
logger.info("benjamin doclist size " + docList.size());
if( docList.size() > 0 ){
logger.info("benjamin documents found " + docList.size());
var doc = docList.get(0);
logger.info("benjamin doc type " + doc.getClass().getName());
var siteList = doc.getFirstValue("sitelist_s");
if( siteList ) {
siteList = siteList.replaceAll(',',' ').trim();
request.addParam("fq","contenturl_en_siteid_ss:(" + siteList + ")");
filterList.push("contenturl_en_siteid_ss:(" + siteList + ")");
}
logger.info("benjamin siteList " + siteList);
var roleList = doc.getFirstValue("rolelist_s");
if( roleList ){
roleList = roleList.replaceAll(',',' ').trim();
request.addParam("fq","contentrole_ss:(" + roleList + ")");
filterList.push("contentrole_ss:(" + roleList + ")");
}
logger.info("benjamin roleList " + roleList);
}
else {
request.addParam("fq","id:0");
filterList.push("id:0");
}
} catch (e) {
logger.info("benjamin " + e.toString());
}
logger.info("benjamin done");
} // end if LDAPID
else {
request.addParam("fq","id:0");
filterList.push("id:0");
}
if( filterList.length > 0 ){
ctx.put("accessfilterlist",JSON.stringify(filterList));
}
}