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);
  }
  @Override
  protected long getActivitySetId(long activityId) {
    try {
      SocialActivitySet activitySet = null;

      SocialActivity activity = SocialActivityLocalServiceUtil.getActivity(activityId);

      if (activity.getType() == SocialActivityKeyConstants.DL_ADD_FILE_ENTRY) {

        activitySet =
            SocialActivitySetLocalServiceUtil.getUserActivitySet(
                activity.getGroupId(), activity.getUserId(),
                activity.getClassNameId(), activity.getType());
      } else if (activity.getType() == SocialActivityKeyConstants.DL_UPDATE_FILE_ENTRY) {

        activitySet =
            SocialActivitySetLocalServiceUtil.getClassActivitySet(
                activity.getUserId(), activity.getClassNameId(),
                activity.getClassPK(), activity.getType());
      }

      if ((activitySet != null) && !isExpired(activitySet, false)) {
        return activitySet.getActivitySetId();
      }
    } catch (Exception e) {
    }

    return 0;
  }
  public void deleteWallEntry(WallEntry wallEntry) throws SystemException {

    // Social

    SocialActivityLocalServiceUtil.deleteActivities(
        WallEntry.class.getName(), wallEntry.getWallEntryId());

    // Entry

    wallEntryPersistence.remove(wallEntry);
  }
  public void doDeleteActivities(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> activityIds,
      SecurityToken securityToken)
      throws Exception {

    for (String activityId : activityIds) {
      long activityIdLong = GetterUtil.getLong(activityId);

      SocialActivityLocalServiceUtil.deleteActivity(activityIdLong);
    }
  }
  protected List<Activity> getActivities(ThemeDisplay themeDisplay, long userId) throws Exception {

    List<Activity> activities = new ArrayList<Activity>();

    List<SocialActivity> socialActivities =
        SocialActivityLocalServiceUtil.getUserActivities(userId, 0, 20);

    for (SocialActivity socialActivity : socialActivities) {
      Activity activity = getActivity(themeDisplay, socialActivity);

      activities.add(activity);
    }

    return activities;
  }
  public List<SocialActivity> getActivities(Long userId, int start, int count)
      throws SystemException {
    List<ActivitySubscription> subscriptions = null;
    // for now no activity selection is made, TODO
    subscriptions = activitySubscriptionPersistence.findByreceiverId(userId);

    if (subscriptions.size() == 0) {
      return new ArrayList<SocialActivity>();
    }

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(SocialActivity.class);
    Criterion crit = null;

    for (ActivitySubscription sub : subscriptions) {
      Map<String, Number> criterion = new HashMap<String, Number>();
      criterion.put("classNameId", sub.getClassNameId());
      criterion.put("classPK", sub.getClassPK());

      if (sub.getType() != null) {
        criterion.put("type", sub.getType());
      }
      Criterion subCriterion = RestrictionsFactoryUtil.allEq(criterion);

      if (sub.getExtraData() != null && sub.getExtraData().length() > 0) {
        subCriterion =
            RestrictionsFactoryUtil.and(
                subCriterion, RestrictionsFactoryUtil.ilike("extraData", sub.getExtraData() + "%"));
      }

      if (crit == null) {
        crit = subCriterion;
      } else {
        crit = RestrictionsFactoryUtil.or(crit, subCriterion);
      }
    }
    query.add(crit).addOrder(OrderFactoryUtil.desc("createDate"));

    List<SocialActivity> activities = new ArrayList<SocialActivity>();
    List<Object> queryResults =
        SocialActivityLocalServiceUtil.dynamicQuery(query, start, start + count - 1);

    for (Object activity : queryResults) {
      activities.add((SocialActivity) activity);
    }

    return activities;
  }
  public WallEntry addWallEntry(
      long groupId, long userId, String comments, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    // Wall entry

    Group group = GroupLocalServiceUtil.getGroup(groupId);
    User user = userLocalService.getUserById(userId);
    Date now = new Date();

    long wallEntryId = counterLocalService.increment();

    WallEntry wallEntry = wallEntryPersistence.create(wallEntryId);

    wallEntry.setGroupId(groupId);
    wallEntry.setCompanyId(user.getCompanyId());
    wallEntry.setUserId(user.getUserId());
    wallEntry.setUserName(user.getFullName());
    wallEntry.setCreateDate(now);
    wallEntry.setModifiedDate(now);
    wallEntry.setComments(comments);

    wallEntryPersistence.update(wallEntry, false);

    // Email

    try {
      sendEmail(wallEntry, themeDisplay);
    } catch (Exception e) {
      throw new SystemException(e);
    }

    // Social

    if (userId != group.getClassPK()) {
      SocialActivityLocalServiceUtil.addActivity(
          userId,
          groupId,
          WallEntry.class.getName(),
          wallEntryId,
          WallActivityKeys.ADD_ENTRY,
          StringPool.BLANK,
          group.getClassPK());
    }

    return wallEntry;
  }
  public Activity doGetActivity(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> fields,
      String activityId,
      SecurityToken securityToken)
      throws Exception {

    ThemeDisplay themeDisplay = getThemeDisplay(securityToken);

    long activityIdLong = GetterUtil.getLong(activityId);

    SocialActivity socialActivity = SocialActivityLocalServiceUtil.getActivity(activityIdLong);

    return getActivity(themeDisplay, socialActivity);
  }
  @Override
  public MicroblogsEntry deleteMicroblogsEntry(MicroblogsEntry microblogsEntry)
      throws PortalException, SystemException {

    // Microblogs entry

    microblogsEntryPersistence.remove(microblogsEntry);

    // Asset

    AssetEntryLocalServiceUtil.deleteEntry(
        MicroblogsEntry.class.getName(), microblogsEntry.getMicroblogsEntryId());

    // Social

    SocialActivityLocalServiceUtil.deleteActivities(
        MicroblogsEntry.class.getName(), microblogsEntry.getMicroblogsEntryId());

    return microblogsEntry;
  }
Beispiel #10
0
  @Override
  public SocialActivityFeedEntry interpret(
      SocialActivitySet activitySet, ServiceContext serviceContext) {

    try {
      List<SocialActivity> activities =
          SocialActivityLocalServiceUtil.getActivitySetActivities(
              activitySet.getActivitySetId(), 0, 1);

      if (!activities.isEmpty()) {
        SocialActivity activity = activities.get(0);

        return doInterpret(activity, serviceContext);
      }
    } catch (Exception e) {
      _log.error("Unable to interpret activity set", e);
    }

    return null;
  }
  @Override
  public void deleteTasksEntry(TasksEntry tasksEntry) throws PortalException, SystemException {

    // Tasks entry

    tasksEntryPersistence.remove(tasksEntry);

    // Asset

    AssetEntryLocalServiceUtil.deleteEntry(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());

    // Message boards

    MBMessageLocalServiceUtil.deleteDiscussionMessages(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());

    // Social

    SocialActivityLocalServiceUtil.deleteActivities(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());
  }
  public MicroblogsEntry addMicroblogsEntry(
      long userId,
      String content,
      int type,
      long receiverUserId,
      long receiverMicroblogsEntryId,
      int socialRelationType,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Microblogs entry

    User user = userPersistence.findByPrimaryKey(userId);

    if (receiverUserId == 0) {
      receiverUserId = userId;
    }

    Date now = new Date();

    validate(type, receiverMicroblogsEntryId);

    long microblogsEntryId = counterLocalService.increment();

    MicroblogsEntry microblogsEntry = microblogsEntryPersistence.create(microblogsEntryId);

    microblogsEntry.setCompanyId(user.getCompanyId());
    microblogsEntry.setUserId(user.getUserId());
    microblogsEntry.setUserName(user.getFullName());
    microblogsEntry.setCreateDate(now);
    microblogsEntry.setModifiedDate(now);
    microblogsEntry.setContent(content);
    microblogsEntry.setType(type);
    microblogsEntry.setReceiverUserId(receiverUserId);
    microblogsEntry.setReceiverMicroblogsEntryId(receiverMicroblogsEntryId);
    microblogsEntry.setSocialRelationType(socialRelationType);

    microblogsEntryPersistence.update(microblogsEntry);

    // Resources

    resourceLocalService.addModelResources(microblogsEntry, serviceContext);

    // Asset

    updateAsset(
        microblogsEntry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());

    // Social

    int activityKey = MicroblogsActivityKeys.ADD_ENTRY;

    if (type == MicroblogsEntryConstants.TYPE_REPLY) {
      activityKey = MicroblogsActivityKeys.REPLY_ENTRY;
    } else if (type == MicroblogsEntryConstants.TYPE_REPOST) {
      activityKey = MicroblogsActivityKeys.REPOST_ENTRY;
    }

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("content", microblogsEntry.getContent());
    extraDataJSONObject.put("receiverMicroblogsEntryId", receiverMicroblogsEntryId);

    SocialActivityLocalServiceUtil.addActivity(
        userId,
        0,
        MicroblogsEntry.class.getName(),
        microblogsEntryId,
        activityKey,
        extraDataJSONObject.toString(),
        receiverUserId);

    // Notification

    if (type == MicroblogsEntryConstants.TYPE_REPLY) {
      sendNotificationEvent(microblogsEntry);
    }

    return microblogsEntry;
  }
Beispiel #13
0
  protected void deleteDuplicateActivities() throws Exception {
    StringBundler sb = new StringBundler(14);

    sb.append("select distinct sa1.* from SocialActivity sa1 ");
    sb.append("inner join SocialActivity sa2 on ");
    sb.append("sa1.activityId != sa2.activityId and ");
    sb.append("sa1.groupId = sa2.groupId and ");
    sb.append("sa1.userId = sa2.userId and ");
    sb.append("sa1.classNameId = sa2.classNameId and ");
    sb.append("sa1.classPK = sa2.classPK and ");
    sb.append("sa1.type_ = sa2.type_ and ");
    sb.append("sa1.extraData = sa2.extraData and ");
    sb.append("sa1.receiverUserId = sa2.receiverUserId ");
    sb.append("where sa1.mirrorActivityId = 0 ");
    sb.append("order by sa1.groupId, sa1.userId, sa1.classNameId, ");
    sb.append("sa1.classPK, sa1.type_, sa1.extraData, ");
    sb.append("sa1.receiverUserId, sa1.createDate desc");

    String sql = sb.toString();

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      long groupId = 0;
      long userId = 0;
      long classNameId = 0;
      long classPK = 0;
      long type = 0;
      String extraData = StringPool.BLANK;
      long receiverUserId = 0;

      while (rs.next()) {
        long curActivityId = rs.getLong("activityId");
        long curGroupId = rs.getLong("groupId");
        long curUserId = rs.getLong("userId");
        long curClassNameId = rs.getLong("classNameId");
        long curClassPK = rs.getLong("classPK");
        long curType = rs.getLong("type_");
        String curExtraData = rs.getString("extraData");
        long curReceiverUserId = rs.getLong("receiverUserId");

        if ((curGroupId == groupId)
            && (curUserId == userId)
            && (curClassNameId == classNameId)
            && (curClassPK == classPK)
            && (curType == type)
            && curExtraData.equals(extraData)
            && (curReceiverUserId == receiverUserId)) {

          SocialActivityLocalServiceUtil.deleteActivity(curActivityId);
        } else {
          groupId = curGroupId;
          userId = curUserId;
          classNameId = curClassNameId;
          classPK = curClassPK;
          type = curType;
          extraData = curExtraData;
          receiverUserId = curReceiverUserId;
        }
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  public TasksEntry addTasksEntry(
      long userId,
      String title,
      int priority,
      long assigneeUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    User user = UserLocalServiceUtil.getUserById(userId);
    long groupId = serviceContext.getScopeGroupId();
    Date now = new Date();

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    long tasksEntryId = CounterLocalServiceUtil.increment();

    TasksEntry tasksEntry = tasksEntryPersistence.create(tasksEntryId);

    tasksEntry.setGroupId(groupId);
    tasksEntry.setCompanyId(user.getCompanyId());
    tasksEntry.setUserId(user.getUserId());
    tasksEntry.setUserName(user.getFullName());
    tasksEntry.setCreateDate(now);
    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);
    tasksEntry.setStatus(TasksEntryConstants.STATUS_OPEN);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        userId,
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    SocialActivityLocalServiceUtil.addActivity(
        userId,
        groupId,
        TasksEntry.class.getName(),
        tasksEntryId,
        TasksActivityKeys.ADD_ENTRY,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }
  public TasksEntry updateTasksEntry(
      long tasksEntryId,
      String title,
      int priority,
      long assigneeUserId,
      long resolverUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      int status,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    Date now = new Date();

    TasksEntry tasksEntry = tasksEntryPersistence.findByPrimaryKey(tasksEntryId);

    User user = UserLocalServiceUtil.getUserById(tasksEntry.getUserId());

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      tasksEntry.setResolverUserId(resolverUserId);
      tasksEntry.setFinishDate(now);
    } else {
      tasksEntry.setResolverUserId(0);
      tasksEntry.setFinishDate(null);
    }

    tasksEntry.setStatus(status);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        tasksEntry.getUserId(),
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    int activity = TasksActivityKeys.UPDATE_ENTRY;

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      activity = TasksActivityKeys.RESOLVE_ENTRY;
    } else if (status == TasksEntryConstants.STATUS_REOPENED) {
      activity = TasksActivityKeys.REOPEN_ENTRY;
    }

    SocialActivityLocalServiceUtil.addActivity(
        serviceContext.getUserId(),
        tasksEntry.getGroupId(),
        TasksEntry.class.getName(),
        tasksEntryId,
        activity,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }