Пример #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;
  }
Пример #2
0
  public Future<Void> createActivity(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> fields,
      Activity activity,
      SecurityToken token)
      throws ProtocolException {

    Session hs = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tran = null;

    try {
      Long startTime = new Date().getTime();

      tran = hs.beginTransaction();

      // check if the person exists
      String user = userId.getUserId(token);
      Person person = (Person) hs.get(Person.class, user);

      if (person == null)
        throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "Person does not exist");

      if (activity.getStreamFaviconUrl() != null
          || activity.getStreamSourceUrl() != null
          || activity.getStreamTitle() != null
          || activity.getStreamUrl() != null)
        throw new ProtocolException(
            HttpServletResponse.SC_BAD_REQUEST, "Creating activity with stream params");

      // create Activity
      com.skt.opensocial.persistence.Activity activityDB =
          this.setActivityDBFromActivity(person, appId, activity);
      activityDB.setPerson(person);

      // auto increment "id" is the activity id
      Integer newId = (Integer) hs.save(activityDB);
      activityDB.setActivityId(newId.toString());

      // set up the posted time
      Long endTime = new Date().getTime();
      activityDB.setPostedTime(new Double(endTime - startTime));

      hs.saveOrUpdate(activityDB);

      // **** insert activity with mediaItems and templateParams separately ****//
      // create MediaItems of the Activity
      List<MediaItem> items = activity.getMediaItems();

      if (items != null) {
        for (MediaItem item : items) {
          com.skt.opensocial.persistence.ActivityMediaItem mediaItemDB =
              this.setMediaItemDBFromMediaItem(user, activityDB.getActivityId(), item);
          hs.saveOrUpdate(mediaItemDB);
        }
      }

      // create TemplateParams of the activity
      Map<String, String> params = activity.getTemplateParams();

      if (params != null) {
        Set<String> keys = params.keySet();
        for (String key : keys) {
          com.skt.opensocial.persistence.ActivityTemplateParam templateParamDB =
              this.setTemplateParamDBFromTemplateParma(
                  user, activityDB.getActivityId(), key, params.get(key));
          hs.saveOrUpdate(templateParamDB);
        }
      }

      tran.commit();

      return ImmediateFuture.newInstance(null);

    } catch (HibernateException e) {
      if (tran != null) tran.rollback();

      throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
    }
  }