Exemple #1
0
 public static boolean existsByAuthUserIdentity(final AuthUserIdentity identity) {
   final ExpressionList<User> exp;
   if (identity instanceof UsernamePasswordAuthUser) {
     exp = getUsernamePasswordAuthUserFind((UsernamePasswordAuthUser) identity);
   } else {
     exp = getAuthUserFind(identity);
   }
   return exp.findRowCount() > 0;
 }
Exemple #2
0
  /**
   * {@code fromProject}의 {@code fromBranch}에서 보낸 가장 최근 코드보내기 요청을 찾는다.
   *
   * <p>fromProject와 toProject가 같은 수도 있다고 가정한다. {@code fromProject}가 fork 프로젝트 일때는 upstream으로 보낸
   * 코드보내기 요청을 포함하여 찾는다.
   *
   * <p>when: 코드 메뉴의 브랜치 탭에서 브랜치 목록을 보여줄 때 특정 브랜치와 관련있는 코드보내기 요청을 찾을 때 사용한다.
   *
   * @param fromProject
   * @param fromBranch
   * @return
   */
  public static PullRequest findTheLatestOneFrom(Project fromProject, String fromBranch) {
    ExpressionList<PullRequest> el =
        finder.where().eq("fromProject", fromProject).eq("fromBranch", fromBranch);

    if (fromProject.isForkedFromOrigin()) {
      el.in("toProject", fromProject, fromProject.originalProject);
    } else {
      el.eq("toProject", fromProject);
    }

    return el.order().desc("number").setMaxRows(1).findUnique();
  }
 /** {@inheritDoc} */
 @Override
 @Transactional(readOnly = true)
 public PagingList<Session> find(
     User user, String name, String orderBy, boolean ascending, int pageSize) {
   // TODO union with sessions where the user has participated
   Query<Session> query = ebean.find(Session.class);
   ExpressionList<Session> expr = query.where().eq("author", user);
   if (!Strings.isNullOrEmpty(name)) {
     expr = expr.ilike("name", name);
   }
   query = ascending ? expr.orderBy().asc(orderBy) : expr.orderBy().desc(orderBy);
   return new EbeanPagingList<Session>(query.findPagingList(pageSize));
 }
Exemple #4
0
  /** finds all patients with a country filter */
  public static List<? extends IPatient> findPatients(
      IRepository<IPatient> patientRepository, String country) {

    ExpressionList<Patient> patientExpressionList =
        QueryProvider.getPatientQuery()
            .select("*")
            .fetch("patientEncounters")
            .fetch("patientEncounters.missionTrip")
            .fetch("patientEncounters.missionTrip.missionCity")
            .fetch("patientEncounters.missionTrip.missionCity.missionCountry")
            .where()
            .eq("patientEncounters.missionTrip.missionCity.missionCountry.name", country);

    return patientExpressionList.findList();
  }
Exemple #5
0
  /**
   * ajax 를 이용한 사용자 검색 요청 헤더의 accept 파라미터에 application/json 값이 없으면 406 응답 응답에 포함되는 데이터 수는
   * MAX_FETCH_USERS 로 제한된다 입력 파라미터 query 가 부분매칭 되는 loginId 목록을 json 형태로 응답
   *
   * @param query 검색어
   * @return
   */
  public static Result users(String query) {
    if (!request().accepts("application/json")) {
      return status(Http.Status.NOT_ACCEPTABLE);
    }

    ExpressionList<User> el = User.find.select("loginId, name").where().disjunction();
    el.icontains("loginId", query);
    el.icontains("name", query);
    el.endJunction();

    int total = el.findRowCount();
    if (total > MAX_FETCH_USERS) {
      el.setMaxRows(MAX_FETCH_USERS);
      response().setHeader("Content-Range", "items " + MAX_FETCH_USERS + "/" + total);
    }

    List<Map<String, String>> users = new ArrayList<>();
    for (User user : el.findList()) {
      StringBuilder sb = new StringBuilder();
      sb.append(String.format("<img class='mention_image' src='%s'>", user.avatarUrl()));
      sb.append(String.format("<b class='mention_name'>%s</b>", user.name));
      sb.append(String.format("<span class='mention_username'> @%s</span>", user.loginId));

      Map<String, String> userMap = new HashMap<>();
      userMap.put("info", sb.toString());
      userMap.put("loginId", user.loginId);
      users.add(userMap);
    }

    return ok(toJson(users));
  }
 /**
  * Update the specified expression list with the specified order by structure
  *
  * @param orderBy an order by structure
  * @param expressionList an expression list
  */
 public static <T> void updateExpressionListWithOrderBy(
     OrderBy<T> orderBy, ExpressionList<T> expressionList) {
   OrderBy<T> currentOrderBy = expressionList.orderBy();
   if (orderBy.getProperties() != null) {
     for (Property property : orderBy.getProperties()) {
       currentOrderBy.add(property);
     }
   }
 }
 /**
  * Return a page of computer
  *
  * @param page Page to display
  * @param pageSize Number of pfps per page
  * @param sortBy Pfp property used for sorting
  * @param order Sort order (either or asc or desc)
  * @param filter Filter applied on the name column
  */
 public static Page<Event> page(
     int page,
     int pageSize,
     String sortBy,
     String order,
     String filter,
     String fieldName,
     User localUser) {
   String queryField = "name";
   if (StringUtils.equals("name", fieldName) || StringUtils.equals("schoolId", fieldName)) {
     queryField = fieldName;
   } else if (StringUtils.equals("status", fieldName)) {
     if (StringUtils.equalsIgnoreCase("NEW", filter)) {
       filter = "1";
     } else if (StringUtils.equalsIgnoreCase("PRIVATE", filter)) {
       filter = "2";
     } else if (StringUtils.equalsIgnoreCase("LOCKED", filter)) {
       filter = "4";
     } else {
       filter = "3";
     }
     queryField = fieldName;
   } else if (StringUtils.equals("userAdmin", fieldName)) {
     queryField = "userAdmin.organization.taxId";
   }
   if (StringUtils.equals("eventName", sortBy)) {
     sortBy = "name";
   }
   if (pageSize > 20) {
     pageSize = 20;
   }
   ExpressionList<Event> query = find.where().ilike(queryField, "%" + filter + "%");
   if (localUser != null) {
     query.eq("userAdmin.id", localUser.id);
   }
   return query
       .orderBy(sortBy + " " + order)
       .select(
           "id, eventEnd, eventStart, status, schoolId, fundraisingEnd, fundraisingStart, goal, name, userAdmin")
       .fetch("userAdmin")
       .findPagingList(pageSize)
       .setFetchAhead(false)
       .getPage(page);
 }
Exemple #8
0
  /**
   * ajax 를 이용한 사용자 검색 요청 헤더의 accept 파라미터에 application/json 값이 없으면 406 응답 응답에 포함되는 데이터 수는
   * MAX_FETCH_USERS 로 제한된다 입력 파라미터 query 가 부분매칭 되는 loginId 목록을 json 형태로 응답
   *
   * @param query 검색어
   * @return
   */
  public static Result users(String query) {
    if (!request().accepts("application/json")) {
      return status(Http.Status.NOT_ACCEPTABLE);
    }

    ExpressionList<User> el = User.find.select("loginId").where().contains("loginId", query);
    int total = el.findRowCount();
    if (total > MAX_FETCH_USERS) {
      el.setMaxRows(MAX_FETCH_USERS);
      response().setHeader("Content-Range", "items " + MAX_FETCH_USERS + "/" + total);
    }

    List<String> loginIds = new ArrayList<>();
    for (User user : el.findList()) {
      loginIds.add(user.loginId);
    }

    return ok(toJson(loginIds));
  }
Exemple #9
0
  /**
   * 프로젝트 제한을 두지 않고 전체 이슈를 대상으로 검색할 때 사용한다.
   *
   * @return ExpressionList<Issue>
   */
  public ExpressionList<Issue> asExpressionList() {
    ExpressionList<Issue> el = Issue.finder.where();

    if (assigneeId != null) {
      if (assigneeId.equals(User.anonymous.id)) {
        el.isNull("assignee");
      } else {
        el.eq("assignee.user.id", assigneeId);
      }
    }

    if (authorId != null) {
      el.eq("authorId", authorId);
    }

    if (StringUtils.isNotBlank(filter)) {
      Junction<Issue> junction = el.disjunction();
      junction.icontains("title", filter).icontains("body", filter);
      List<Object> ids = Issue.finder.where().icontains("comments.contents", filter).findIds();
      if (!ids.isEmpty()) {
        junction.idIn(ids);
      }
      junction.endJunction();
    }

    if (commentedCheck) {
      el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS);
    }

    State st = State.getValue(state);
    if (st.equals(State.OPEN) || st.equals(State.CLOSED)) {
      el.eq("state", st);
    }

    if (orderBy != null) {
      el.orderBy(orderBy + " " + orderDir);
    }

    return el;
  }
Exemple #10
0
  /**
   * 특정 프로젝트를 대상으로 검색 표현식을 만든다.
   *
   * @return ExpressionList<Issue>
   */
  public ExpressionList<Issue> asExpressionList(Project project) {
    ExpressionList<Issue> el = Issue.finder.where();
    if (project != null) {
      el.eq("project.id", project.id);
    }
    if (StringUtils.isNotBlank(filter)) {
      Junction<Issue> junction = el.disjunction();
      junction.icontains("title", filter).icontains("body", filter);
      List<Object> ids = null;
      if (project == null) {
        ids = Issue.finder.where().icontains("comments.contents", filter).findIds();
      } else {
        ids =
            Issue.finder
                .where()
                .eq("project.id", project.id)
                .icontains("comments.contents", filter)
                .findIds();
      }
      if (!ids.isEmpty()) {
        junction.idIn(ids);
      }
      junction.endJunction();
    }

    if (authorId != null) {
      if (authorId.equals(User.anonymous.id)) {
        el.isNull("authorId");
      } else {
        el.eq("authorId", authorId);
      }
    }

    if (assigneeId != null) {
      if (assigneeId.equals(User.anonymous.id)) {
        el.isNull("assignee");
      } else {
        el.eq("assignee.user.id", assigneeId);
        el.eq("assignee.project.id", project.id);
      }
    }

    if (milestoneId != null) {
      if (milestoneId.equals(Milestone.NULL_MILESTONE_ID)) {
        el.isNull("milestone");
      } else {
        el.eq("milestone.id", milestoneId);
      }
    }

    if (commentedCheck) {
      el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS);
    }

    State st = State.getValue(state);
    if (st.equals(State.OPEN) || st.equals(State.CLOSED)) {
      el.eq("state", st);
    }

    if (CollectionUtils.isNotEmpty(labelIds)) {
      el.add(LabelSearchUtil.createLabelSearchExpression(el.query(), labelIds));
    }

    if (orderBy != null) {
      el.orderBy(orderBy + " " + orderDir);
    }

    return el;
  }
Exemple #11
0
 /**
  * This method filters permission refusals by name and returns a list of filtered
  * PermissionRefusal objects.
  *
  * @param name
  * @return
  */
 public static List<PermissionRefusal> filterByName(String name) {
   List<PermissionRefusal> res = new ArrayList<PermissionRefusal>();
   ExpressionList<PermissionRefusal> ll = find.where().icontains(Const.NAME, name);
   res = ll.findList();
   return res;
 }
  @Test
  public void matchingBBTest() {

    /*
    ====================================================
    BLACK BOX TEST  : SEE /Z/report/report.pdf,  page 16
    ====================================================
    */

    Coordinate coorATest = new Coordinate(50.669715, 4.602624);
    Coordinate coorBTest = new Coordinate(50.667892, 4.619073);
    User userTest =
        new User(
            "loginTest",
            "Mister",
            "Nobody",
            "*****@*****.**",
            "0123-456",
            0,
            null,
            null,
            null,
            null,
            null);
    Date arrTimeTest = new Date(2013, 01, 04, 15, 00);
    Traject trajectTest =
        new Traject(
            1, // Seats
            15, // TotalCost
            null, // Request
            userTest, // User
            null, // Dep PP
            null, // Arr PP
            null); // Proposal
    Request reqTest =
        new Request(
            coorATest, // Coor departure
            coorBTest, // Coor arrival
            "Place Galilee 6 1348 Louvain-La-Neuve", // Adress departure
            "Cour des Fleurets 1348 Louvain-La-Neuve", // Adress arrival
            arrTimeTest, // Arrival time
            1, // Seats
            60, // Time tolerance
            3000, // Walk tolerance in m
            5, // Price tolerance
            userTest, // User
            trajectTest); // Traject
    trajectTest.setRequest(reqTest);

    // BB Test : msg-1
    ArrayList<Traject> response = controllers.Matching.match(reqTest);
    /*for(Traject traj : response){
        Assert.fail("Requete n est pas dans la base de donnees mais matching retourne un trajet");
    }*/
    reqTest.getUser().addRequest(reqTest);
    reqTest.save();
    reqTest.getUser().save();

    // BB Test : msg-2
    ArrayList<Traject> response2 = controllers.Matching.match(reqTest);
    for (Traject traj : response2) {
      ExpressionList<Proposal> res = Proposal.find.where().eq("id", traj.getProposal().getId());
      if (res.findRowCount() < 1) {
        Assert.fail("Proposal n est pas dans la base de donnees mais matching retourne un trajet");
      }
    }

    // BB Test : msg-3 + msg-4
    for (Traject traj : response2) {
      PickupPoint depPP = traj.getDeparturePP().getPickupPoint();
      PickupPoint arrPP = traj.getArrivalPP().getPickupPoint();
      if (PickupPoint.find.where().eq("id", depPP.getId()) != depPP) {
        Assert.fail("Departure PickUpPoint pas dans la base de donnees");
      }
      if (PickupPoint.find.where().eq("id", arrPP.getId()) != arrPP) {
        Assert.fail("Arrival PickUpPoint pas dans la base de donnees");
      }
    }

    for (Traject traj : response2) {
      // BB Test : msg-5
      double walkBegin =
          Matching.distance(
              traj.getDeparturePP().getPickupPoint().getCoordinates(),
              reqTest.getTraject().getDeparturePP().getPickupPoint().getCoordinates());
      double walkEnd =
          Matching.distance(
              reqTest.getTraject().getArrivalPP().getPickupPoint().getCoordinates(),
              traj.getArrivalPP().getPickupPoint().getCoordinates());
      if (walkBegin + walkEnd > 3000) {
        Assert.fail("La tolerance de distance de marche n est pas respectee");
      }

      // BB Test : msg-6
      Date maxiTime = new Date(2013, 01, 04, 16, 00);
      if (traj.getArrivalPP().getTime().after(maxiTime)) {
        Assert.fail("Heure d arrivee du passager depasse la tolerance d heure d arrivee");
      }

      // BB Test : msg-7
      if (traj.getReservedSeats() - 1 < 0) {
        Assert.fail("Pas assez de sieges libres dans la proposition pour satisfaire la requete");
      }

      // BB Test : msg-8
      if (traj.getTotalCost() > 5) {
        Assert.fail("Tolerance en cout non respectee.");
      }
    }
  }
Exemple #13
0
 /**
  * This method filters roles by name and returns a list of filtered Role objects.
  *
  * @param name
  * @return
  */
 public static List<Role> filterByName(String name) {
   List<Role> res = new ArrayList<Role>();
   ExpressionList<Role> ll = find.where().icontains("name", name);
   res = ll.findList();
   return res;
 }