public SocialActivitySet addActivitySet(long activityId) throws PortalException, SystemException {

    // Activity set

    SocialActivity activity = socialActivityPersistence.findByPrimaryKey(activityId);

    long activitySetId = counterLocalService.increment();

    SocialActivitySet activitySet = socialActivitySetPersistence.create(activitySetId);

    activitySet.setGroupId(activity.getGroupId());
    activitySet.setCompanyId(activity.getCompanyId());
    activitySet.setUserId(activity.getUserId());
    activitySet.setCreateDate(activity.getCreateDate());
    activitySet.setModifiedDate(activity.getCreateDate());
    activitySet.setClassName(activity.getClassName());
    activitySet.setClassPK(activity.getClassPK());
    activitySet.setType(activity.getType());
    activitySet.setActivityCount(1);

    socialActivitySetPersistence.update(activitySet);

    // Activity

    activity.setActivitySetId(activitySetId);

    socialActivityPersistence.update(activity);

    return activitySet;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    SocialActivitySet existingSocialActivitySet =
        _persistence.fetchByPrimaryKey(newSocialActivitySet.getPrimaryKey());

    Assert.assertEquals(existingSocialActivitySet, newSocialActivitySet);
  }
コード例 #4
0
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySet socialActivitySet = _persistence.create(pk);

    Assert.assertNotNull(socialActivitySet);

    Assert.assertEquals(socialActivitySet.getPrimaryKey(), pk);
  }
コード例 #5
0
  @Test
  public void testRemove() throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    _persistence.remove(newSocialActivitySet);

    SocialActivitySet existingSocialActivitySet =
        _persistence.fetchByPrimaryKey(newSocialActivitySet.getPrimaryKey());

    Assert.assertNull(existingSocialActivitySet);
  }
コード例 #6
0
  @Override
  protected String getBody(SocialActivitySet activitySet, ServiceContext serviceContext)
      throws Exception {

    if (activitySet.getType() == SocialActivityKeyConstants.DL_UPDATE_FILE_ENTRY) {

      return getBody(activitySet.getClassName(), activitySet.getClassPK(), serviceContext);
    }

    return super.getBody(activitySet, serviceContext);
  }
コード例 #7
0
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newSocialActivitySet.getPrimaryKey());

    Map<Serializable, SocialActivitySet> socialActivitySets =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, socialActivitySets.size());
    Assert.assertEquals(
        newSocialActivitySet, socialActivitySets.get(newSocialActivitySet.getPrimaryKey()));
  }
  public void decrementActivityCount(long activitySetId) throws PortalException, SystemException {

    if (activitySetId == 0) {
      return;
    }

    SocialActivitySet activitySet = socialActivitySetPersistence.findByPrimaryKey(activitySetId);

    if (activitySet.getActivityCount() == 1) {
      socialActivitySetPersistence.remove(activitySetId);

      return;
    }

    activitySet.setActivityCount(activitySet.getActivityCount() - 1);

    socialActivitySetPersistence.update(activitySet);
  }
コード例 #9
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivitySet.class, SocialActivitySet.class.getClassLoader());

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("activitySetId", newSocialActivitySet.getActivitySetId()));

    List<SocialActivitySet> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    SocialActivitySet existingSocialActivitySet = result.get(0);

    Assert.assertEquals(existingSocialActivitySet, newSocialActivitySet);
  }
コード例 #10
0
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newSocialActivitySet.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, SocialActivitySet> socialActivitySets =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, socialActivitySets.size());
    Assert.assertEquals(
        newSocialActivitySet, socialActivitySets.get(newSocialActivitySet.getPrimaryKey()));
  }
  public void incrementActivityCount(long activitySetId, long activityId)
      throws PortalException, SystemException {

    // Activity set

    SocialActivitySet activitySet = socialActivitySetPersistence.findByPrimaryKey(activitySetId);

    SocialActivity activity = socialActivityPersistence.findByPrimaryKey(activityId);

    activitySet.setModifiedDate(activity.getCreateDate());

    activitySet.setActivityCount(activitySet.getActivityCount() + 1);

    socialActivitySetPersistence.update(activitySet);

    // Activity

    activity.setActivitySetId(activitySetId);

    socialActivityPersistence.update(activity);
  }
コード例 #12
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    SocialActivitySet newSocialActivitySet = addSocialActivitySet();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivitySet.class, SocialActivitySet.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("activitySetId"));

    Object newActivitySetId = newSocialActivitySet.getActivitySetId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("activitySetId", new Object[] {newActivitySetId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingActivitySetId = result.get(0);

    Assert.assertEquals(existingActivitySetId, newActivitySetId);
  }
コード例 #13
0
  @Override
  protected Object[] getTitleArguments(
      String groupName,
      SocialActivitySet activitySet,
      String link,
      String title,
      ServiceContext serviceContext)
      throws Exception {

    int activityCount = activitySet.getActivityCount();

    if (activitySet.getType() == SocialActivityKeyConstants.DL_UPDATE_FILE_ENTRY) {

      String folderLink = getFolderLink(activitySet.getClassPK(), serviceContext);

      if (Validator.isNotNull(folderLink)) {
        return new Object[] {activityCount, folderLink};
      }
    }

    return new Object[] {activityCount};
  }
コード例 #14
0
  @Override
  protected String getTitlePattern(String groupName, SocialActivitySet activitySet)
      throws Exception {

    String titlePattern = StringPool.BLANK;

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

      titlePattern = "uploaded-x-new-documents";
    } else if (activitySet.getType() == SocialActivityKeyConstants.DL_UPDATE_FILE_ENTRY) {

      titlePattern = "made-x-updates-to-a-document";

      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(activitySet.getClassPK());

      if (fileEntry.getFolderId() > 0) {
        titlePattern = titlePattern.concat("-in-the-x-folder");
      }
    } else {
      return StringPool.BLANK;
    }

    return titlePattern;
  }
コード例 #15
0
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    SocialActivitySet newSocialActivitySet1 = addSocialActivitySet();
    SocialActivitySet newSocialActivitySet2 = addSocialActivitySet();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newSocialActivitySet1.getPrimaryKey());
    primaryKeys.add(newSocialActivitySet2.getPrimaryKey());

    Map<Serializable, SocialActivitySet> socialActivitySets =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, socialActivitySets.size());
    Assert.assertEquals(
        newSocialActivitySet1, socialActivitySets.get(newSocialActivitySet1.getPrimaryKey()));
    Assert.assertEquals(
        newSocialActivitySet2, socialActivitySets.get(newSocialActivitySet2.getPrimaryKey()));
  }
コード例 #16
0
  protected SocialActivitySet addSocialActivitySet() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySet socialActivitySet = _persistence.create(pk);

    socialActivitySet.setGroupId(RandomTestUtil.nextLong());

    socialActivitySet.setCompanyId(RandomTestUtil.nextLong());

    socialActivitySet.setUserId(RandomTestUtil.nextLong());

    socialActivitySet.setCreateDate(RandomTestUtil.nextLong());

    socialActivitySet.setModifiedDate(RandomTestUtil.nextLong());

    socialActivitySet.setClassNameId(RandomTestUtil.nextLong());

    socialActivitySet.setClassPK(RandomTestUtil.nextLong());

    socialActivitySet.setType(RandomTestUtil.nextInt());

    socialActivitySet.setExtraData(RandomTestUtil.randomString());

    socialActivitySet.setActivityCount(RandomTestUtil.nextInt());

    _socialActivitySets.add(_persistence.update(socialActivitySet));

    return socialActivitySet;
  }
コード例 #17
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySet newSocialActivitySet = _persistence.create(pk);

    newSocialActivitySet.setGroupId(RandomTestUtil.nextLong());

    newSocialActivitySet.setCompanyId(RandomTestUtil.nextLong());

    newSocialActivitySet.setUserId(RandomTestUtil.nextLong());

    newSocialActivitySet.setCreateDate(RandomTestUtil.nextLong());

    newSocialActivitySet.setModifiedDate(RandomTestUtil.nextLong());

    newSocialActivitySet.setClassNameId(RandomTestUtil.nextLong());

    newSocialActivitySet.setClassPK(RandomTestUtil.nextLong());

    newSocialActivitySet.setType(RandomTestUtil.nextInt());

    newSocialActivitySet.setExtraData(RandomTestUtil.randomString());

    newSocialActivitySet.setActivityCount(RandomTestUtil.nextInt());

    _socialActivitySets.add(_persistence.update(newSocialActivitySet));

    SocialActivitySet existingSocialActivitySet =
        _persistence.findByPrimaryKey(newSocialActivitySet.getPrimaryKey());

    Assert.assertEquals(
        existingSocialActivitySet.getActivitySetId(), newSocialActivitySet.getActivitySetId());
    Assert.assertEquals(existingSocialActivitySet.getGroupId(), newSocialActivitySet.getGroupId());
    Assert.assertEquals(
        existingSocialActivitySet.getCompanyId(), newSocialActivitySet.getCompanyId());
    Assert.assertEquals(existingSocialActivitySet.getUserId(), newSocialActivitySet.getUserId());
    Assert.assertEquals(
        existingSocialActivitySet.getCreateDate(), newSocialActivitySet.getCreateDate());
    Assert.assertEquals(
        existingSocialActivitySet.getModifiedDate(), newSocialActivitySet.getModifiedDate());
    Assert.assertEquals(
        existingSocialActivitySet.getClassNameId(), newSocialActivitySet.getClassNameId());
    Assert.assertEquals(existingSocialActivitySet.getClassPK(), newSocialActivitySet.getClassPK());
    Assert.assertEquals(existingSocialActivitySet.getType(), newSocialActivitySet.getType());
    Assert.assertEquals(
        existingSocialActivitySet.getExtraData(), newSocialActivitySet.getExtraData());
    Assert.assertEquals(
        existingSocialActivitySet.getActivityCount(), newSocialActivitySet.getActivityCount());
  }