Package com.bugyal.imentor.frontend.shared

Examples of com.bugyal.imentor.frontend.shared.SearchResponse


  @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;
View Full Code Here


  @Override
  public SearchResponse feedToMe() throws MeException {
    QuotaService qs = QuotaServiceFactory.getQuotaService();
    long start = qs.getCpuTimeInMegaCycles();
    long t = System.currentTimeMillis();
    SearchResponse response = null;
    try {
      long temp = t;
      Participant pi = pm.findParticipantByEmail(getUserId());
      long endtime = System.currentTimeMillis();
      LOG.info("For TOME findParticipantByEmail(getUserId()) "
          + (endtime - temp));
      if (pi == null) {
        return new SearchResponse();
      }
      response = filterList(pi.getLocation().getLat(), pi.getLocation()
          .getLon(), pi.getLoc().getLocationString(), pi.getLoc()
          .getActiveRadius(), pi.getHasSubjects(), pi
          .getNeedSubjects());
View Full Code Here

  @Override
  public SearchResponse localActivity() {
    QuotaService qs = QuotaServiceFactory.getQuotaService();
    long start = qs.getCpuTimeInMegaCycles();
    long t = System.currentTimeMillis();
    SearchResponse response = new SearchResponse();
    try {
      List<SearchResult> has = new ArrayList<SearchResult>();
      List<SearchResult> need = new ArrayList<SearchResult>();

      long temp = System.currentTimeMillis();
      Participant pi = pm.findParticipantByEmail(getUserId());
      LOG.info("For Local Activity findParticipantByEmail(getUserId()) "
          + (System.currentTimeMillis() - temp));

      if (pi == null) {
        return response;
      }
      Location location = new Location(pi.getLocation().getLat(), pi
          .getLocation().getLon(), pi.getLoc().getLocationString(),
          pi.getLoc().getActiveRadius());

      temp = System.currentTimeMillis();
      List<Participant> participants = pm
          .searchParticipantsByLocation(location);
      LOG.info("For Local Activity searchParticipantsByLocation(location) "
              + (System.currentTimeMillis() - temp));
      for (Participant p : participants) {
        double distance = GeocellUtils.distance(pi.getLocation(), p
            .getLocation());
        has.add(new SearchResult(ValueObjectGenerator.create(p), true,
            p.getHasSubjects(), distance));
        need.add(new SearchResult(ValueObjectGenerator.create(p),
            false, p.getNeedSubjects(), distance));
      }

      temp = System.currentTimeMillis();
      List<Opportunity> opportunities = om.allOpportunites(location);
      LOG.info("For Local Activity allOpportunites(location) "
          + (System.currentTimeMillis() - temp));
      for (Opportunity o : opportunities) {
        need.add(new SearchResult(ValueObjectGenerator.create(o), o
            .getSubjects(), GeocellUtils.distance(pi.getLocation(),
            o.getLocation())));
      }
      response.setHas(has);
      response.setNeed(need);
      response = filterMe(pi, response);
      long end = qs.getCpuTimeInMegaCycles();
      double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
      LOG.info("Local Activity CPU Usage : " + cpuSeconds);
      return response;
View Full Code Here

    return response;
  }

  private SearchResponse filterMe(Participant pi, SearchResponse response) {
    String email = pi.getEmail();
    SearchResponse result = new SearchResponse();
    List<SearchResult> hasSub = new ArrayList<SearchResult>();
    List<SearchResult> needSub = new ArrayList<SearchResult>();

    for (SearchResult has : response.getHas()) {
      if (!(has.getP().getEmail().equals(email))) {
        hasSub.add(has);
      }
    }
    for (SearchResult need : response.getNeed()) {
      if (need.isTypeParticipant()) {
        if (!(need.getP().getEmail().equals(email))) {
          needSub.add(need);
        }
      } else {
        needSub.add(need);
      }
    }
    result.setHas(hasSub);
    result.setNeed(needSub);
    return result;
  }
View Full Code Here

TOP

Related Classes of com.bugyal.imentor.frontend.shared.SearchResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.