@Override
public SearchResponse filterList(double latitude, double longitude,
String strlocation, int radius, List<String> hasSubs,
List<String> needSubs) {
SearchResponse response = new SearchResponse();
Participant pi;
Point pt = new Point(latitude, longitude);
try {
Set<String> hasSubjects = new HashSet<String>();
Set<String> needSubjects = new HashSet<String>();
for (String s : hasSubs) {
hasSubjects.add(s);
}
for (String s : needSubs) {
needSubjects.add(s);
}
List<SearchResult> has = new ArrayList<SearchResult>();
List<SearchResult> need = new ArrayList<SearchResult>();
Location location = new Location(latitude, longitude, strlocation,
radius);
long temp = System.currentTimeMillis();
List<Participant> participants = pm.searchParticipantsBySubjects(
needSubs, location, true);
pi= pm.findParticipantByEmail(getUserId());
LOG.info("For TOME searchParticipantsBySubjects(needSubs,location, true) "
+ (System.currentTimeMillis() - temp));
for (Participant p : participants) {
List<String> matchingSubs = new ArrayList<String>();
for (String s : p.getHasSubjects()) {
if (needSubjects.contains(s)) {
matchingSubs.add(s);
}
}
has.add(new SearchResult(ValueObjectGenerator.create(p), true,
matchingSubs, GeocellUtils
.distance(pt, p.getLocation())));
}
temp = System.currentTimeMillis();
participants = pm.searchParticipantsBySubjects(hasSubs, location,
false);
LOG.info("For TOME searchParticipantsBySubjects(hasSubs, location, false) "
+ (System.currentTimeMillis() - temp));
for (Participant p : participants) {
List<String> matchingSubs = new ArrayList<String>();
for (String s : p.getNeedSubjects()) {
if (hasSubjects.contains(s)) {
matchingSubs.add(s);
}
}
need.add(new SearchResult(ValueObjectGenerator.create(p),
false, matchingSubs, GeocellUtils.distance(pt, p
.getLocation())));
}
temp = System.currentTimeMillis();
List<Opportunity> opportunities = om.searchOpportunities(location,
hasSubs);
LOG.info("For TOME searchOpportunities(location, hasSubs) "
+ (System.currentTimeMillis() - temp));
for (Opportunity o : opportunities) {
List<String> matchingSubs = new ArrayList<String>();
for (String s : o.getSubjects()) {
if (hasSubjects.contains(s)) {
matchingSubs.add(s);
}
}
need.add(new SearchResult(ValueObjectGenerator.create(o),
matchingSubs, GeocellUtils
.distance(pt, o.getLocation())));
}
for(SearchResult s: need) {
if(s.isTypeParticipant()) {
if(s.getP().getEmail().equals(pi.getEmail())) {
need.remove(s);
}
}
}
for(SearchResult s: has) {
if(s.getP().getEmail().equals(pi.getEmail())) {
has.remove(s);
}
}
response.setHas(has);
response.setNeed(need);
return response;
} catch (MentorException e) {
e.printStackTrace();
}
return response;