protected Activity getActivity(ThemeDisplay themeDisplay, SocialActivity socialActivity)
      throws Exception {

    Activity activity = null;

    String className = socialActivity.getClassName();

    if (className.equals(Activity.class.getName())) {
      activity = getExternalActivity(socialActivity);
    } else {
      activity =
          new ActivityImpl(
              String.valueOf(socialActivity.getClassPK()),
              String.valueOf(socialActivity.getUserId()));

      HttpServletRequest request = HttpServletRequestThreadLocal.getHttpServletRequest();

      request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);

      ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

      serviceContext.setCompanyId(themeDisplay.getCompanyId());
      serviceContext.setUserId(themeDisplay.getUserId());

      SocialActivityFeedEntry socialActivityFeedEntry = null;
      SocialActivityInterpreterLocalServiceUtil.interpret(
          StringPool.BLANK, socialActivity, serviceContext);

      activity.setBody(socialActivityFeedEntry.getBody());
      activity.setTitle(socialActivityFeedEntry.getTitle());
      activity.setUrl(socialActivityFeedEntry.getLink());
    }

    return activity;
  }
Example #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;
  }