Esempio n. 1
0
  private com.skt.opensocial.persistence.Activity setActivityDBFromActivity(
      Person user, String appId, Activity activity) {
    com.skt.opensocial.persistence.Activity activityDB =
        new com.skt.opensocial.persistence.Activity();

    activityDB.setAppId(appId);

    activityDB.setBody(activity.getBody());
    activityDB.setBodyId(activity.getBodyId());
    activityDB.setExternalId(activity.getExternalId());

    if (activity.getPriority() != null) activityDB.setPriority(new Double(activity.getPriority()));
    else activityDB.setPriority(new Double(0));

    activityDB.setStreamFaviconUrl(activity.getStreamFaviconUrl());
    activityDB.setStreamSourceUrl(activity.getStreamSourceUrl());
    activityDB.setStreamTitle(activity.getStreamTitle());
    activityDB.setStreamUrl(activity.getStreamUrl());
    activityDB.setTitle(activity.getTitle());

    // there should one of Title or TitleId
    if (activityDB.getTitle() == null) activityDB.setTitleId(activity.getTitleId());

    activityDB.setUpdated(activity.getUpdated());
    activityDB.setUrl(activity.getUrl());
    activityDB.setPerson(user);

    return activityDB;
  }
Esempio 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;
  }