public void doCreateActivity(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> fields,
      Activity activity,
      SecurityToken securityToken)
      throws Exception {

    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));

    String activityAppId = activity.getAppId();

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    SerializerUtil.copyProperties(activity, extraDataJSONObject, _ACTIVITY_FIELDS);

    SocialActivityLocalServiceUtil.addActivity(
        userIdLong,
        0L,
        Activity.class.getName(),
        activity.getPostedTime(),
        activityAppId.hashCode(),
        extraDataJSONObject.toString(),
        0L);
  }
Exemplo n.º 2
0
  /* (non-Javadoc)
   * @see org.apache.shindig.social.opensocial.spi.ActivityService#createActivity(org.apache.shindig.social.opensocial.spi.UserId, org.apache.shindig.social.opensocial.spi.GroupId, java.lang.String, java.util.Set, org.apache.shindig.social.opensocial.model.Activity, org.apache.shindig.auth.SecurityToken)
   */
  public Future<Void> createActivity(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> fields,
      Activity activity,
      SecurityToken token)
      throws ProtocolException {
    String uid = SPIUtils.getUserList(userId, token);

    EntityManager entityManager = getEntityManager();
    try {
      activity.setPostedTime(new Date().getTime());
      activity.setAppId(appId);
      activity.setUserId(uid);
      activity.setUpdated(new Date());
      activity.setId("activity" + SPIUtils.generateId(uid + activity.getPostedTime()));
      activity.setUrl(activity.getUrl() + activity.getId());
      // TODO How should transactions be managed? Should samples be using warp-persist instead?
      if (!entityManager.getTransaction().isActive()) {
        entityManager.getTransaction().begin();
      }
      entityManager.persist(activity);
      entityManager.getTransaction().commit();

    } catch (Exception e) {
      throw new ProtocolException(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create activity", e);
    } finally {
      entityManager.close();
    }

    return null;
  }