@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

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

    Assert.assertEquals(existingRatingsEntry, newRatingsEntry);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    RatingsEntry ratingsEntry = _persistence.create(pk);

    Assert.assertNotNull(ratingsEntry);

    Assert.assertEquals(ratingsEntry.getPrimaryKey(), pk);
  }
  protected RatingsEntry addRatingsEntry(
      long entryId,
      long companyId,
      long userId,
      String userName,
      Date createDate,
      Date modifiedDate,
      long classNameId,
      long classPK,
      double score)
      throws SystemException {

    RatingsEntry ratingsEntry = ratingsEntryPersistence.create(entryId);

    ratingsEntry.setCompanyId(companyId);
    ratingsEntry.setUserId(userId);
    ratingsEntry.setUserName(userName);
    ratingsEntry.setCreateDate(createDate);
    ratingsEntry.setModifiedDate(modifiedDate);
    ratingsEntry.setClassNameId(classNameId);
    ratingsEntry.setClassPK(classPK);
    ratingsEntry.setScore(score);

    return ratingsEntryPersistence.update(ratingsEntry);
  }
  @Test
  public void testRemove() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

    _persistence.remove(newRatingsEntry);

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

    Assert.assertNull(existingRatingsEntry);
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

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

    primaryKeys.add(newRatingsEntry.getPrimaryKey());

    Map<Serializable, RatingsEntry> ratingsEntries = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ratingsEntries.size());
    Assert.assertEquals(newRatingsEntry, ratingsEntries.get(newRatingsEntry.getPrimaryKey()));
  }
  @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);
  }
  public void addRatingsEntries(Class<?> clazz, long classPK) throws SystemException {

    List<RatingsEntry> ratingsEntries =
        RatingsEntryLocalServiceUtil.getEntries(clazz.getName(), classPK);

    if (ratingsEntries.size() == 0) {
      return;
    }

    for (RatingsEntry entry : ratingsEntries) {
      entry.setUserUuid(entry.getUserUuid());
    }

    _ratingsEntriesMap.put(getPrimaryKeyString(clazz, classPK), ratingsEntries);
  }
  /**
   * Adds the ratings entry to the database. Also notifies the appropriate model listeners.
   *
   * @param ratingsEntry the ratings entry
   * @return the ratings entry that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public RatingsEntry addRatingsEntry(RatingsEntry ratingsEntry) throws SystemException {
    ratingsEntry.setNew(true);

    return ratingsEntryPersistence.update(ratingsEntry);
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(RatingsEntry.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("entryId", newRatingsEntry.getEntryId()));

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

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

    RatingsEntry existingRatingsEntry = result.get(0);

    Assert.assertEquals(existingRatingsEntry, newRatingsEntry);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

    long pk = RandomTestUtil.nextLong();

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

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

    Map<Serializable, RatingsEntry> ratingsEntries = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ratingsEntries.size());
    Assert.assertEquals(newRatingsEntry, ratingsEntries.get(newRatingsEntry.getPrimaryKey()));
  }
  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());
  }
예제 #12
0
  public void addRatingsEntries(Class<?> clazz, long classPK) throws SystemException {

    List<RatingsEntry> ratingsEntries =
        RatingsEntryLocalServiceUtil.getEntries(clazz.getName(), classPK);

    if (ratingsEntries.size() == 0) {
      return;
    }

    Iterator<RatingsEntry> itr = ratingsEntries.iterator();

    while (itr.hasNext()) {
      RatingsEntry entry = itr.next();

      entry.setUserUuid(entry.getUserUuid());
    }

    _ratingsEntriesMap.put(getPrimaryKeyString(clazz, classPK), ratingsEntries);
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static RatingsEntry toModel(RatingsEntrySoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    RatingsEntry model = new RatingsEntryImpl();

    model.setEntryId(soapModel.getEntryId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setClassNameId(soapModel.getClassNameId());
    model.setClassPK(soapModel.getClassPK());
    model.setScore(soapModel.getScore());

    return model;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof RatingsEntry)) {
      return false;
    }

    RatingsEntry ratingsEntry = (RatingsEntry) obj;

    long primaryKey = ratingsEntry.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(RatingsEntry.class, _dynamicQueryClassLoader);

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

    Object newEntryId = newRatingsEntry.getEntryId();

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

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

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

    Object existingEntryId = result.get(0);

    Assert.assertEquals(existingEntryId, newEntryId);
  }
  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);
    }
  }
  @Override
  public int compareTo(RatingsEntry ratingsEntry) {
    long primaryKey = ratingsEntry.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  /**
   * Adds the ratings entry to the database. Also notifies the appropriate model listeners.
   *
   * @param ratingsEntry the ratings entry
   * @return the ratings entry that was added
   * @throws SystemException if a system exception occurred
   */
  public RatingsEntry addRatingsEntry(RatingsEntry ratingsEntry) throws SystemException {
    ratingsEntry.setNew(true);

    ratingsEntry = ratingsEntryPersistence.update(ratingsEntry, false);

    Indexer indexer = IndexerRegistryUtil.getIndexer(getModelClassName());

    if (indexer != null) {
      try {
        indexer.reindex(ratingsEntry);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }
    }

    return ratingsEntry;
  }
예제 #19
0
  protected String getRatingsEntryPath(
      PortletDataContext portletDataContext,
      String className,
      String classPK,
      RatingsEntry ratingsEntry) {

    StringBundler sb = new StringBundler(8);

    sb.append(portletDataContext.getRootPath());
    sb.append("/ratings/");
    sb.append(PortalUtil.getClassNameId(className));
    sb.append(CharPool.FORWARD_SLASH);
    sb.append(classPK);
    sb.append(CharPool.FORWARD_SLASH);
    sb.append(ratingsEntry.getEntryId());
    sb.append(".xml");

    return sb.toString();
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    RatingsEntry newRatingsEntry1 = addRatingsEntry();
    RatingsEntry newRatingsEntry2 = addRatingsEntry();

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

    primaryKeys.add(newRatingsEntry1.getPrimaryKey());
    primaryKeys.add(newRatingsEntry2.getPrimaryKey());

    Map<Serializable, RatingsEntry> ratingsEntries = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, ratingsEntries.size());
    Assert.assertEquals(newRatingsEntry1, ratingsEntries.get(newRatingsEntry1.getPrimaryKey()));
    Assert.assertEquals(newRatingsEntry2, ratingsEntries.get(newRatingsEntry2.getPrimaryKey()));
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    RatingsEntry newRatingsEntry = addRatingsEntry();

    _persistence.clearCache();

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

    Assert.assertEquals(
        Long.valueOf(existingRatingsEntry.getUserId()),
        ReflectionTestUtil.<Long>invoke(
            existingRatingsEntry, "getOriginalUserId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingRatingsEntry.getClassNameId()),
        ReflectionTestUtil.<Long>invoke(
            existingRatingsEntry, "getOriginalClassNameId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingRatingsEntry.getClassPK()),
        ReflectionTestUtil.<Long>invoke(
            existingRatingsEntry, "getOriginalClassPK", new Class<?>[0]));
  }
  /**
   * Updates the ratings entry in the database. Also notifies the appropriate model listeners.
   *
   * @param ratingsEntry the ratings entry to update
   * @param merge whether to merge the ratings entry with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the ratings entry that was updated
   * @throws SystemException if a system exception occurred
   */
  public RatingsEntry updateRatingsEntry(RatingsEntry ratingsEntry, boolean merge)
      throws SystemException {
    ratingsEntry.setNew(false);

    return ratingsEntryPersistence.update(ratingsEntry, merge);
  }
  /**
   * Adds the ratings entry to the database. Also notifies the appropriate model listeners.
   *
   * @param ratingsEntry the ratings entry to add
   * @return the ratings entry that was added
   * @throws SystemException if a system exception occurred
   */
  public RatingsEntry addRatingsEntry(RatingsEntry ratingsEntry) throws SystemException {
    ratingsEntry.setNew(true);

    return ratingsEntryPersistence.update(ratingsEntry, false);
  }
  @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()));
  }
  protected RatingsEntry addRatingsEntry() throws Exception {
    long pk = RandomTestUtil.nextLong();

    RatingsEntry ratingsEntry = _persistence.create(pk);

    ratingsEntry.setUuid(RandomTestUtil.randomString());

    ratingsEntry.setCompanyId(RandomTestUtil.nextLong());

    ratingsEntry.setUserId(RandomTestUtil.nextLong());

    ratingsEntry.setUserName(RandomTestUtil.randomString());

    ratingsEntry.setCreateDate(RandomTestUtil.nextDate());

    ratingsEntry.setModifiedDate(RandomTestUtil.nextDate());

    ratingsEntry.setClassNameId(RandomTestUtil.nextLong());

    ratingsEntry.setClassPK(RandomTestUtil.nextLong());

    ratingsEntry.setScore(RandomTestUtil.nextDouble());

    ratingsEntry.setLastPublishDate(RandomTestUtil.nextDate());

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

    return ratingsEntry;
  }