@Before
  public void setUp() {
    datastoreHelper.setUp();
    ObjectifyFilter.complete();

    Client.create(client);
    sgp = Group.create(client, "Singapore", User.SUPER_USER);
    assertEquals(1, sgp.groupId);

    kl = Group.create(client, "KL", User.SUPER_USER);
    assertEquals(2, kl.groupId);

    validUser = User.create(client, "*****@*****.**", sgp.groupId, User.SUPER_USER);

    userWithSendMailPermissionForSgp =
        User.create(client, "*****@*****.**", sgp.groupId, User.SUPER_USER);
    User.addGroupLevelPrivilege(
        client,
        sgp.groupId,
        userWithSendMailPermissionForSgp.email,
        GroupLevelPrivilege.SEND_EMAIL,
        User.SUPER_USER);

    sgpTeachers = List.createRestricted(client, sgp.groupId, "Sgp Teachers", null, User.SUPER_USER);

    ContactProp c = new ContactProp();
    c.email = "*****@*****.**";
    c.asOfyyyymmdd = 20141026;
    c.firstName = "Sathya";
    sathya = Member.create(client, sgp.groupId, c, false, User.SUPER_USER);

    c.firstName = "Sharmila";
    c.mobilePhone = "+6593849384";
    c.email = null;
    sharmila = Member.create(client, sgp.groupId, c, false, User.SUPER_USER);
    assertEquals("Sharmila", sharmila.contact.firstName);

    c.email = "*****@*****.**";
    murugavel = Member.create(client, sgp.groupId, c, false, User.SUPER_USER);
    assertEquals("*****@*****.**", murugavel.contact.email);

    // add sathya and sharmila to sgpTeachers
    Member.addOrDeleteList(client, sathya.memberId, sgpTeachers.listId, true, User.SUPER_USER);
    Member.addOrDeleteList(client, sharmila.memberId, sgpTeachers.listId, true, User.SUPER_USER);
    Member.subscribeGroup(client, sathya.memberId, sgp.groupId, User.SUPER_USER);
    Member.subscribeGroup(client, sharmila.memberId, sgp.groupId, User.SUPER_USER);

    ObjectifyFilter.complete();
  }
示例#2
0
  public static PracticeProp create(String client, String displayName, String login) {

    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    ensureNotNullNotEmpty(displayName, "displayName is null or empty");
    String name = Utils.removeSpaceUnderscoreBracketAndHyphen(displayName.toLowerCase());

    List<Key<PracticeEntity>> keys =
        ofy(client).load().type(PracticeEntity.class).filter("name", name).keys().list();

    if (keys.size() != 0)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + displayName + "]");

    String key = getUniqueKey(client, name);
    long val = MemcacheServiceFactory.getMemcacheService().increment(key, 1, (long) 0);

    if (val != 1)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a group with name [" + displayName + "]");

    PracticeEntity entity = new PracticeEntity();
    entity.practiceId = Sequence.getNext(client, SequenceType.PRACTICE);
    entity.name = name;
    entity.displayName = displayName;
    ofy(client).save().entity(entity).now();

    return entity.toProp();
  }
示例#3
0
  public static void delete(String client, long practiceId, String login) {

    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    // there should not be any program type referencing this
    throw new APIException()
        .status(Status.ERROR_NOT_IMPLEMENTED)
        .message("This functionality is not implemented yet");
  }
  protected final void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    StringBuffer buf = req.getRequestURL();
    if (req.getQueryString() != null) {
      buf.append('?').append(req.getQueryString());
    }

    AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(buf.toString());

    String code = responseUrl.getCode();
    if (responseUrl.getError() != null) {
      String state = URLDecoder.decode(req.getParameter("state"), "UTF-8");
      String[] params = state.split("\\|");
      resp.sendRedirect(params[1]);
    } else if (code == null) {
      resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      resp.getWriter().print("Missing authorization code");
    } else {
      String redirectUri = ServletUtils.getRedirectUri(req);
      lock.lock();
      try {
        if (flow == null) {
          flow = ServletUtils.newFlow();
        }
        TokenResponse response = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute();

        HttpSession sess = req.getSession(true);
        Credential credential = flow.createAndStoreCredential(response, sess.getId());
        String[] params = URLDecoder.decode(req.getParameter("state"), "UTF-8").split("\\|");
        String client = params[2];
        String email = ServletUtils.getEmail(credential);
        UserEntity user = User.get(client, email);
        if (user != null) {
          sess.setAttribute("login", email);
          sess.setAttribute("loginType", "google");
        }

        resp.sendRedirect(params[0]);
      } finally {
        lock.unlock();
      }
    }
  }
示例#5
0
  public static PracticeProp rename(
      String client, long practiceId, String newDisplayName, String login) {
    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    PracticeEntity entity = safeGet(client, practiceId);

    ensureNotNullNotEmpty(newDisplayName, "newDisplayName is null or empty");
    String newName = Utils.removeSpaceUnderscoreBracketAndHyphen(newDisplayName.toLowerCase());

    if (entity.name.equals(newName)) {
      // ideally should be inside a transaction
      entity.displayName = newDisplayName;
      ofy(client).save().entity(entity).now();
      return entity.toProp();
    }

    List<Key<PracticeEntity>> keys =
        ofy(client).load().type(PracticeEntity.class).filter("name", newName).keys().list();
    if (keys.size() != 0)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + newDisplayName + "]");

    String key = getUniqueKey(client, newName);
    long val = MemcacheServiceFactory.getMemcacheService().increment(key, 1, (long) 0);

    if (val != 1)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + newDisplayName + "]");

    // ideally should be inside a transaction
    entity.name = newName;
    entity.displayName = newDisplayName;
    ofy(client).save().entity(entity).now();

    return entity.toProp();
  }