*/
@Override
public Map<String, ? extends Object> processFilter(boolean inJson)
{
List<FilterResult> result = new ArrayList<FilterResult>();
JSONArray resultJson = new JSONArray();
boolean areNew = false;
//groups containers
JSONArray groupsJson = new JSONArray();
Map<String,FilterResult> newResults = new HashMap<String, FilterResult>();
String query = SscfRdfQuery.RDF_GET_RECOM_BY_PERSON.toString(this.person);
String queryFilterOut = SscfRdfQuery.RDF_GET_RECOM_BY_PERSON_FILTEROUT.toString(this.person);
//this.searchType.getWordNetQuery(this.person,wncOne.getURI());
System.out.println(query);
QueryResultTable results = null;
QueryResultTable resTmp = null;
List<String> filterOut = new ArrayList<String>();
List<String> inserted = new ArrayList<String>();
try
{
results = DbFace.getModel().querySelect(query,"SPARQL");
resTmp = DbFace.getModel().querySelect(queryFilterOut,"SPARQL");
for(QueryRow qr:resTmp)
filterOut.add(qr.getValue(resTmp.getVariables().get(0)).toString());
}
catch (Exception e1)
{
//do nothing
}
if(getNew)
{
String prolog,trustPolicies;
//properties set by the SSCFTrustSampleServlet
prolog = System.getProperty("RealTrust.XSBEnginePath");
trustPolicies = System.getProperty("sscftrust.policies");
SSCFTrustEngineExecuter stee = new SSCFTrustEngineExecuter(prolog,trustPolicies,null);
stee.execute(person);
//QueryResultsTable resultsAfter = SesameDbFace.getDbFace().performTableQuery(query);
QueryResultTable resultsAfter=null;
try
{
resultsAfter = DbFace.getModel().querySelect(query,"SPARQL");
}
catch (Exception e1)
{
//
}
if(resultsAfter!=null&&(results==null || getIteratorLength(resultsAfter.iterator())!=getIteratorLength(results.iterator())))
{
for(QueryRow qr : resultsAfter) {
FilterResult fr = new FilterResult();
String uriTmp = qr.getValue(resultsAfter.getVariables().get(0)).toString();
if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
{
fr.setResourceUri(uriTmp);
inserted.add(uriTmp);
fr.setResourceType(S3B_SSCF.Directory);
fr.setLabel(qr.getLiteralValue(resultsAfter.getVariables().get(1)));
try {
fr.setContent(qr.getLiteralValue(resultsAfter.getVariables().get(2)));
} catch (Exception e) {
fr.setContent(null);
}
try {
fr.setCreator(qr.getValue(resultsAfter.getVariables().get(3)).toString());
} catch (Exception e) {
fr.setCreator(null);
}
newResults.put(fr.getResourceUri(),fr);
}
}
areNew = true;
}
else
results = null;
}
inserted.clear();
//=== generate normal results ===
if(results!=null&&!inJson)
{
for(QueryRow qr : results) {
FilterResult fr = new FilterResult();
String uriTmp = qr.getValue(results.getVariables().get(0)).toString();
if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
{
fr.setResourceUri(uriTmp);
inserted.add(uriTmp);
fr.setResourceType(S3B_SSCF.Directory);
fr.setLabel(qr.getLiteralValue(results.getVariables().get(1)));
try {
fr.setContent(qr.getLiteralValue(results.getVariables().get(2)));
}
catch (Exception e) {
fr.setContent(null);
}
try {
fr.setCreator(qr.getValue(results.getVariables().get(3)).toString());
}
catch (Exception e) {
fr.setCreator(null);
}
if(areNew)
{
fr.setGroup("others");
if(newResults.get(fr.getResourceUri())!=null)
newResults.remove(fr.getResourceUri());
}
result.add(fr);
}
}
}
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>();
if(!inJson)