Ejemplo n.º 1
0
  private void attachBasicInfo(Context ctx, Record pageRec) {
    long pageId = pageRec.getInt("page_id", 0);

    // viewer_can_update
    if (ctx.getViewerId() >= 0 && pageRec.getInt("creator") == ctx.getViewerId()) {
      pageRec.put("viewer_can_update", true);
    } else {
      pageRec.put("viewer_can_update", false);
    }

    // logo & cover url prefix
    addImagePrefix(imagePattern, pageRec);

    // followers count
    int followersCount = GlobalLogics.getFriendship().getFollowersCount(ctx, Long.toString(pageId));
    pageRec.put("followers_count", followersCount);

    // followed
    long[] followedIds =
        GlobalLogics.getFriendship().isFollowedPages(ctx, ctx.getViewerId(), new long[] {pageId});
    pageRec.put("followed", ArrayUtils.isNotEmpty(followedIds));
  }
Ejemplo n.º 2
0
  @TraceCall
  @Override
  public Record createPage(Context ctx, Record pageRec) {
    long viewerId = ctx.getViewerId();
    GlobalLogics.getAccount().checkUserIds(ctx, Long.toString(viewerId));
    long associatedId = pageRec.checkGetInt("associated_id");
    //        if (associatedId > 0) {
    //            int userType = Constants.getUserTypeById(associatedId);
    //            if (userType == Constants.PUBLIC_CIRCLE_OBJECT || userType ==
    // Constants.EVENT_OBJECT) {
    //                // TODO: group exists?
    //            } else if (userType == Constants.USER_OBJECT) {
    //                // TODO: user exists?
    //            } else {
    //                throw new ServerException(WutongErrors.PAGE_ILLEGAL_ASSOCIATED_ID);
    //            }
    //        }

    long now = DateUtils.nowMillis();
    String sql =
        new SQLBuilder.Insert()
            .insertIgnoreInto(pageTable)
            .values(
                new Record()
                    .set("created_time", now)
                    .set("updated_time", now)
                    .set("destroyed_time", 0L)
                    .set("email_domain1", pageRec.getString("email_domain1"))
                    .set("email_domain2", pageRec.getString("email_domain2"))
                    .set("email_domain3", pageRec.getString("email_domain3"))
                    .set("email_domain4", pageRec.getString("email_domain4"))
                    .set("type", pageRec.getString("type"))
                    .set("name", pageRec.getString("name"))
                    .set("name_en", pageRec.getString("name_en"))
                    .set("email", pageRec.getString("email"))
                    .set("website", pageRec.getString("website"))
                    .set("tel", pageRec.getString("tel"))
                    .set("fax", pageRec.getString("fax"))
                    .set("zip_code", pageRec.getString("zip_code"))
                    .set("small_logo_url", pageRec.getString("small_logo_url"))
                    .set("logo_url", pageRec.getString("logo_url"))
                    .set("large_logo_url", pageRec.getString("large_logo_url"))
                    .set("small_cover_url", pageRec.getString("small_cover_url"))
                    .set("cover_url", pageRec.getString("cover_url"))
                    .set("large_cover_url", pageRec.getString("large_cover_url"))
                    .set("description", pageRec.getString("description"))
                    .set("description_en", pageRec.getString("description_en"))
                    .set("creator", viewerId)
                    .set("associated_id", associatedId)
                    .set("free_circle_ids", pageRec.getString("free_circle_ids")))
            .toString();

    SQLExecutor se = getSqlExecutor();
    ObjectHolder<Long> idHolder = new ObjectHolder<Long>(0L);
    se.executeUpdate(sql, idHolder);
    if (idHolder.value == 0L)
      throw new ServerException(WutongErrors.PAGE_SERVICE_ERROR_CODE, "Create page error");

    GlobalLogics.getFriendship().followPage(ctx, ctx.getViewerId(), idHolder.value);
    return getPage(ctx, idHolder.value);
  }