コード例 #1
0
  /**
   * This method lists all the entities inserted in datastore. It uses HTTP GET method.
   *
   * @param q Query parameter.<br>
   *     Examples : 1. [email protected]<br>
   *     2. [email protected]<br>
   *     3. [email protected],[email protected]<br>
   * @return A CollectionResponse class containing the list of all entities persisted.
   */
  @ApiMethod(name = "appointments.listAppointment")
  public CollectionResponse<Appointment> listAppointment(@Named("q") @Nullable String q) {

    List<Appointment> appointments = null;
    if (q == null) {
      appointments = ofy().load().type(Appointment.class).list();
    } else {
      String[] conditions = q.split(",");
      LoadType<Appointment> loadType = ofy().load().type(Appointment.class);
      Query<Appointment> query = null;
      for (String condition : conditions) {
        String[] conditionKeyValue = condition.split("=");
        if (conditionKeyValue[0].equalsIgnoreCase("doctor")) {
          if (query == null) query = loadType.filter("doctorEmail", conditionKeyValue[1]);
          else query = query.filter("doctorEmail", conditionKeyValue[1]);
        } else if (conditionKeyValue[0].equalsIgnoreCase("user")) {

          if (query == null) query = loadType.filter("userEmail", conditionKeyValue[1]);
          else query = query.filter("userEmail", conditionKeyValue[1]);
        }
      }
      if (query != null) {
        appointments = query.list();
      } else {
        appointments = loadType.list();
      }
    }
    return new CollectionResponse.Builder<Appointment>().setItems(appointments).build();
  }
コード例 #2
0
 /**
  * Returns an Objectify Query object for the specified filters.
  *
  * @return an Objectify Query.
  */
 @ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
 public Query<Conference> getQuery() {
   // First check the feasibility of inequality filters.
   checkFilters();
   Query<Conference> query = ofy().load().type(Conference.class);
   if (inequalityFilter == null) {
     // Order by name.
     query = query.order("name");
   } else {
     // If we have any inequality filters, order by the field first.
     query = query.order(inequalityFilter.field.getFieldName());
     query = query.order("name");
   }
   for (Filter filter : this.filters) {
     // Applies filters in order.
     if (filter.field.fieldType == FieldType.STRING) {
       query =
           query.filter(
               String.format(
                   "%s %s", filter.field.getFieldName(), filter.operator.getQueryOperator()),
               filter.value);
     } else if (filter.field.fieldType == FieldType.INTEGER) {
       query =
           query.filter(
               String.format(
                   "%s %s", filter.field.getFieldName(), filter.operator.getQueryOperator()),
               Integer.parseInt(filter.value));
     }
   }
   LOG.info(query.toString());
   return query;
 }
コード例 #3
0
 /**
  * List all entities.
  *
  * @param cursor used for pagination to determine which page to return
  * @param limit the maximum number of entries to return
  * @return a response that encapsulates the result list and the next page token/cursor
  */
 @ApiMethod(name = "list", path = "schooldetails", httpMethod = ApiMethod.HttpMethod.GET)
 public CollectionResponse<schooldetails> list(
     @Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
   limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
   Query<schooldetails> query = ofy().load().type(schooldetails.class).limit(limit);
   if (cursor != null) {
     query = query.startAt(Cursor.fromWebSafeString(cursor));
   }
   QueryResultIterator<schooldetails> queryIterator = query.iterator();
   List<schooldetails> schooldetailsList = new ArrayList<schooldetails>(limit);
   while (queryIterator.hasNext()) {
     schooldetailsList.add(queryIterator.next());
   }
   return CollectionResponse.<schooldetails>builder()
       .setItems(schooldetailsList)
       .setNextPageToken(queryIterator.getCursor().toWebSafeString())
       .build();
 }
コード例 #4
0
ファイル: Search.java プロジェクト: eolszewski/MentorMatch
  public static SearchResult performSearch(SearchRequest sr) {
    // TODO: alter order based on user input
    // TODO: disallow searching on input not filled out in a user profile
    // TODO: call method by string name to get rid of if statemetns

    Mentee mentee = OfyService.ofy().load().type(Mentee.class).id(sr.mentee).get();
    Query<Mentee> q =
        OfyService.ofy()
            .load()
            .type(
                Mentee.class); // TODO: Decide what happens when the user does not select anything.
    q = q.filter("Email !=", sr.mentee); // TODO: optimize this

    for (String param : sr.getParameters()) {

      if (param.equals("Majors")) {
        q = q.filter("Majors in", mentee.getMajors());
      }
      if (param.equals("ZipCode")) {
        q = q.filter("ZipCode", mentee.getZipCode());
      }
      if (param.equals("Interests")) {
        q = q.filter("Interests in", mentee.getInterests());
      }
      if (param.equals("Current_Courses")) {
        q = q.filter("Current_Courses in", mentee.getCurrentCourses());
      }
      if (param.equals("Past_Courses")) {
        q = q.filter("Past_Courses in", mentee.getPastCourses());
      }
      if (param.equals("Classification")) {
        q = q.filter("Classification", mentee.getClassification());
      }
      ArrayList<String> SearchTerms = new ArrayList<String>();
      StringTokenizer st = new StringTokenizer(param, " ");
      while (st.hasMoreElements()) {
        SearchTerms.add((st.nextElement().toString()).replaceAll("\\W", "").toLowerCase());
      }
      if (SearchTerms.contains("muscle")) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Weight Lifting");
        q = q.filter("Interests in", list);
      }
      if (SearchTerms.contains("lifts")) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Weight Lifting");
        q = q.filter("Interests in", list);
      }
      if (SearchTerms.contains("ee")) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Electrical Engineering");
        q = q.filter("Majors in", list);
        list.remove(0);
        if (SearchTerms.indexOf("ee") != (SearchTerms.size() - 1)) {
          list.add("EE " + SearchTerms.get((SearchTerms.indexOf("ee") + 1)).toUpperCase());
          Query<Mentee> q2 = q;
          q = q.filter("Past_Courses in", list);
          q2 = q2.filter("Current_Courses in", list);
          ArrayList<Mentee> union = new ArrayList<Mentee>();
          for (Mentee m : q) union.add(m);
          for (Mentee m : q2) {
            if (!union.contains(m)) union.add(m);
          }
          SearchResult result = new SearchResult();
          result.setMatches(union);
          return result;
        }
      }
      if (SearchTerms.contains("party")
          || SearchTerms.contains("frat")
          || SearchTerms.contains("greek")
          || SearchTerms.contains("social")
          || SearchTerms.contains("fraternity")) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Greek Life");
        list.add("Partying");
        q = q.filter("Interests in", list);
      }
    }

    SearchResult result = new SearchResult();
    result.setMatches(q.list());
    return result;
  }
コード例 #5
0
ファイル: DatabaseFilter.java プロジェクト: timothyb89/frcdb
 public <T> Query<T> apply(Query<T> l) {
   return l.filter(property + " " + condition, value);
 }
コード例 #6
0
 public List<ComentarioDto> getComentarios() {
   return query.list();
 }
コード例 #7
0
  /**
   * Exposed as `GET /api/photos`.
   *
   * <p>Accepts the following request parameters.
   *
   * <p>'photoId': id of the requested photo. Will return a single Photo. 'themeId': id of a theme.
   * Will return the collection of photos for the specified theme. 'userId': id of the owner of the
   * photo. Will return the collection of photos for that user. The keyword ‘me’ can be used and
   * will be converted to the logged in user. Requires auth. 'friends': value evaluated to boolean,
   * if true will filter only photos from friends of the logged in user. Requires auth.
   *
   * <p>Returns the following JSON response representing a list of Photos.
   *
   * <p>[ { "id":0, "ownerUserId":0, "ownerDisplayName":"", "ownerProfileUrl":"",
   * "ownerProfilePhoto":"", "themeId":0, "themeDisplayName":"", "numVotes":0, "voted":false, //
   * Whether or not the current user has voted on this. "created":0, "fullsizeUrl":"",
   * "thumbnailUrl":"", "voteCtaUrl":"", // URL for Vote interactive post button.
   * "photoContentUrl":"" // URL for Google crawler to hit to get info. }, ... ]
   *
   * <p>Issues the following errors along with corresponding HTTP response codes: 401: "Unauthorized
   * request" (if certain parameters are present in the request)
   *
   * @see javax.servlet.http.HttpServlet#doGet( javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
      BASE_URL = getBaseUrlFromRequest(req);
      String photoId = req.getParameter("photoId");
      String themeId = req.getParameter("themeId");
      String userIdParam = req.getParameter("userId");
      Long userId;
      Long currentUserId = null;
      if (req.getSession().getAttribute(CURRENT_USER_SESSION_KEY) != null) {
        currentUserId =
            Long.parseLong(req.getSession().getAttribute(CURRENT_USER_SESSION_KEY).toString());
      }
      boolean showFriends = Boolean.parseBoolean(req.getParameter("friends"));
      Query<Photo> q = ofy().load().type(Photo.class);
      if (photoId != null) {
        // Get the photo with the given ID and return it.
        Photo photo = q.filter("id", Long.parseLong(photoId)).first().get();
        sendResponse(req, resp, photo);
      } else {
        if (userIdParam != null) {
          // If the key word me is used, retrieve the current user from the session
          // The user needs to be authenticated to use 'me'
          if (userIdParam.equals("me")) {
            checkAuthorization(req);
            userId = currentUserId;
          } else {
            userId = Long.parseLong(userIdParam);
          }
          if (showFriends) {
            checkAuthorization(req);
            // Get all photos for the user's friends.
            User user = ofy().load().type(User.class).filterKey(User.key(userId)).first().get();
            List<Long> friendIds = user.getFriendIds();
            if (friendIds.size() > 30) {
              friendIds = friendIds.subList(0, 30);
            }
            if (friendIds.size() > 0) {
              q = q.filter("ownerUserId in", friendIds);
            } else {
              List<Photo> emptyList = new ArrayList<Photo>();
              // If there are no friends for the user, return an empty list
              sendResponse(req, resp, emptyList, "photohunt#photos");
              return;
            }
          } else {
            // Get all photos for the user.
            q = q.filter("ownerUserId", userId);
          }
        }
        if (themeId != null) {
          // Limit photos to just those for the given theme.
          q = q.filter("themeId", Long.parseLong(themeId));
        }
        List<Photo> photos = q.list();

        if (currentUserId != null) {
          // Build Hash map of voted photos
          List<Vote> userVotes =
              ofy().load().type(Vote.class).filter("ownerUserId", currentUserId).list();
          HashMap<Long, Boolean> userVotesTable = new HashMap<Long, Boolean>(userVotes.size());
          Iterator<Vote> votesIterator = userVotes.iterator();
          while (votesIterator.hasNext()) {
            userVotesTable.put(votesIterator.next().getPhotoId(), true);
          }
          // Check if user voted for each photo
          Iterator<Photo> photosIterator = photos.iterator();
          while (photosIterator.hasNext()) {
            Photo current = photosIterator.next();
            current.setVoted(userVotesTable.containsKey(current.getId()));
          }
        }
        sendResponse(req, resp, photos, "photohunt#photos");
      }
    } catch (UserNotAuthorizedException e) {
      sendError(resp, 401, "Unauthorized request");
    }
  }