@Override
  public void checkDuplicateTrashEntry(TrashEntry trashEntry, long containerModelId, String newName)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(trashEntry.getClassPK());

    if (containerModelId == TrashEntryConstants.DEFAULT_CONTAINER_ID) {
      containerModelId = page.getNodeId();
    }

    String restoredTitle = page.getTitle();

    if (Validator.isNotNull(newName)) {
      restoredTitle = newName;
    }

    String originalTitle = TrashUtil.stripTrashNamespace(restoredTitle);

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.fetchPageResource(containerModelId, originalTitle);

    if (pageResource != null) {
      DuplicateEntryException dee = new DuplicateEntryException();

      WikiPage duplicatePage = WikiPageLocalServiceUtil.getPage(pageResource.getResourcePrimKey());

      dee.setDuplicateEntryId(duplicatePage.getPageId());
      dee.setOldName(duplicatePage.getTitle());
      dee.setTrashEntryId(trashEntry.getEntryId());

      throw dee;
    }
  }
  public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    WikiPageResource newWikiPageResource = _persistence.create(pk);

    newWikiPageResource.setUuid(randomString());

    newWikiPageResource.setNodeId(nextLong());

    newWikiPageResource.setTitle(randomString());

    _persistence.update(newWikiPageResource, false);

    WikiPageResource existingWikiPageResource =
        _persistence.findByPrimaryKey(newWikiPageResource.getPrimaryKey());

    assertEquals(existingWikiPageResource.getUuid(), newWikiPageResource.getUuid());
    assertEquals(
        existingWikiPageResource.getResourcePrimKey(), newWikiPageResource.getResourcePrimKey());
    assertEquals(existingWikiPageResource.getNodeId(), newWikiPageResource.getNodeId());
    assertEquals(existingWikiPageResource.getTitle(), newWikiPageResource.getTitle());
  }
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    WikiPageResource newWikiPageResource = addWikiPageResource();

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

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("resourcePrimKey", newWikiPageResource.getResourcePrimKey()));

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

    assertEquals(1, result.size());

    WikiPageResource existingWikiPageResource = result.get(0);

    assertEquals(existingWikiPageResource, newWikiPageResource);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    WikiPageResource newWikiPageResource = addWikiPageResource();

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

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

    Object newResourcePrimKey = newWikiPageResource.getResourcePrimKey();

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

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

    assertEquals(1, result.size());

    Object existingResourcePrimKey = result.get(0);

    assertEquals(existingResourcePrimKey, newResourcePrimKey);
  }