}
else if(results!=null)
{
int i=0;
for(QueryRow qr : results) {
JSONObject jo = new JSONObject();
String uriTmp = qr.getValue(results.getVariables().get(0)).toString();
if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
{
i++;
jo.put("uri", uriTmp);
inserted.add(uriTmp);
jo.put("type", S3B_SSCF.Directory);
jo.put("label", qr.getLiteralValue(results.getVariables().get(1)));
try {
jo.put("content", qr.getLiteralValue(results.getVariables().get(2)).toString());
}
catch (Exception e) {
jo.put("content",null);
}
try {
jo.put("creator", qr.getValue(results.getVariables().get(3)).toString());
}
catch (Exception e) {
jo.put("creator",null);
}
if(areNew)
{
jo.put("group","others");
if(newResults.get(uriTmp)!=null)
newResults.remove(uriTmp);
}
resultJson.add(jo);
}
}
//and now the groups
if(i>0&&areNew)
{
JSONObject group = new JSONObject();
group.put("uri", "others");
group.put("name","others");
//group.put("type");
group.put("mean","Existing recommendations");
group.put("count", i);
groupsJson.add(group);
}
}
//=== generate new results ===
for(FilterResult fr:newResults.values())
{
if(!inJson)
result.add(fr);
else
{
JSONObject jo = new JSONObject();
jo.put("uri", fr.getResourceUri());
jo.put("type", fr.getResourceType());
jo.put("label", fr.getLabel());
jo.put("content", fr.getCreator());
jo.put("creator", fr.getCreator());
jo.put("group","new");
resultJson.add(jo);
}
}
if(newResults.size()>0&&inJson)
{
JSONObject group = new JSONObject();
group.put("uri", "new");
group.put("name","new");
//group.put("type");
group.put("mean","New recommendations");
group.put("count", newResults.size());
groupsJson.add(0,group);
}
Map<String,Object> finalResult = new HashMap<String,Object>();