示例#1
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;
  }