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

    RatingsEntry newRatingsEntry = _persistence.create(pk);

    newRatingsEntry.setUuid(RandomTestUtil.randomString());

    newRatingsEntry.setCompanyId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserName(RandomTestUtil.randomString());

    newRatingsEntry.setCreateDate(RandomTestUtil.nextDate());

    newRatingsEntry.setModifiedDate(RandomTestUtil.nextDate());

    newRatingsEntry.setClassNameId(RandomTestUtil.nextLong());

    newRatingsEntry.setClassPK(RandomTestUtil.nextLong());

    newRatingsEntry.setScore(RandomTestUtil.nextDouble());

    newRatingsEntry.setLastPublishDate(RandomTestUtil.nextDate());

    _ratingsEntries.add(_persistence.update(newRatingsEntry));

    RatingsEntry existingRatingsEntry =
        _persistence.findByPrimaryKey(newRatingsEntry.getPrimaryKey());

    Assert.assertEquals(existingRatingsEntry.getUuid(), newRatingsEntry.getUuid());
    Assert.assertEquals(existingRatingsEntry.getEntryId(), newRatingsEntry.getEntryId());
    Assert.assertEquals(existingRatingsEntry.getCompanyId(), newRatingsEntry.getCompanyId());
    Assert.assertEquals(existingRatingsEntry.getUserId(), newRatingsEntry.getUserId());
    Assert.assertEquals(existingRatingsEntry.getUserName(), newRatingsEntry.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getCreateDate()),
        Time.getShortTimestamp(newRatingsEntry.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getModifiedDate()),
        Time.getShortTimestamp(newRatingsEntry.getModifiedDate()));
    Assert.assertEquals(existingRatingsEntry.getClassNameId(), newRatingsEntry.getClassNameId());
    Assert.assertEquals(existingRatingsEntry.getClassPK(), newRatingsEntry.getClassPK());
    AssertUtils.assertEquals(existingRatingsEntry.getScore(), newRatingsEntry.getScore());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getLastPublishDate()),
        Time.getShortTimestamp(newRatingsEntry.getLastPublishDate()));
  }
コード例 #2
0
  protected void importRatings(long oldClassNameId, long oldClassPK, long classNameId, long classPK)
      throws SystemException {

    List<RatingsEntry> ratingsEntries =
        ratingsEntryPersistence.findByC_C(oldClassNameId, oldClassPK);

    for (RatingsEntry ratingsEntry : ratingsEntries) {
      addRatingsEntry(
          counterLocalService.increment(),
          ratingsEntry.getCompanyId(),
          ratingsEntry.getUserId(),
          ratingsEntry.getUserName(),
          ratingsEntry.getCreateDate(),
          ratingsEntry.getModifiedDate(),
          classNameId,
          classPK,
          ratingsEntry.getScore());
    }

    RatingsStats ratingsStats = ratingsStatsPersistence.fetchByC_C(oldClassNameId, oldClassPK);

    if (ratingsStats == null) {
      return;
    }

    addRatingsStats(
        counterLocalService.increment(),
        classNameId,
        classPK,
        ratingsStats.getTotalEntries(),
        ratingsStats.getTotalScore(),
        ratingsStats.getAverageScore());
  }
コード例 #3
0
  @Test
  public void testRatingScore1IsValidScore() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    RatingsEntry ratingsEntry =
        RatingsEntryLocalServiceUtil.updateEntry(
            TestPropsValues.getUserId(),
            RandomTestUtil.randomString(),
            RandomTestUtil.randomLong(),
            1,
            serviceContext);

    Assert.assertEquals(1, ratingsEntry.getScore(), 0.001);
  }
コード例 #4
0
  public void importRatingsEntries(Class<?> clazz, long classPK, long newClassPK)
      throws PortalException, SystemException {

    List<RatingsEntry> ratingsEntries = _ratingsEntriesMap.get(getPrimaryKeyString(clazz, classPK));

    if (ratingsEntries == null) {
      return;
    }

    ServiceContext serviceContext = new ServiceContext();

    for (RatingsEntry ratingsEntry : ratingsEntries) {
      long userId = getUserId(ratingsEntry.getUserUuid());

      serviceContext.setCreateDate(ratingsEntry.getCreateDate());
      serviceContext.setModifiedDate(ratingsEntry.getModifiedDate());

      RatingsEntryLocalServiceUtil.updateEntry(
          userId, clazz.getName(), newClassPK, ratingsEntry.getScore(), serviceContext);
    }
  }