/**
   * Moves the trash entry with the entity class name and primary key, restoring it to a new
   * location identified by the destination container model ID.
   *
   * <p>This method throws a {@link TrashPermissionException} if the user did not have the
   * permission to perform one of the necessary operations. The exception is created with a type
   * specific to the operation:
   *
   * <ul>
   *   <li>{@link TrashPermissionException#MOVE} - if the user did not have permission to move the
   *       trash entry to the new destination
   *   <li>{@link TrashPermissionException#RESTORE} - if the user did not have permission to restore
   *       the trash entry
   * </ul>
   *
   * @param className the class name of the entity
   * @param classPK the primary key of the entity
   * @param destinationContainerModelId the primary key of the new location
   * @param serviceContext the service context to be applied (optionally <code>null</code>)
   * @throws PortalException if a matching trash entry could not be found, if the user did not have
   *     permission to move the trash entry to the new location, if the user did not have permission
   *     to restore the trash entry, if a duplicate trash entry exists at the new location, or if a
   *     portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public void moveEntry(
      String className,
      long classPK,
      long destinationContainerModelId,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    PermissionChecker permissionChecker = getPermissionChecker();

    TrashEntry entry = trashEntryLocalService.getEntry(className, classPK);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (!trashHandler.hasTrashPermission(
        permissionChecker, entry.getGroupId(), destinationContainerModelId, TrashActionKeys.MOVE)) {

      throw new TrashPermissionException(TrashPermissionException.MOVE);
    }

    if (trashHandler.isInTrash(classPK)
        && !trashHandler.hasTrashPermission(
            permissionChecker, 0, classPK, TrashActionKeys.RESTORE)) {

      throw new TrashPermissionException(TrashPermissionException.RESTORE);
    }

    trashHandler.checkDuplicateTrashEntry(entry, destinationContainerModelId, StringPool.BLANK);

    if (trashHandler.isInTrash(classPK)) {
      trashHandler.moveTrashEntry(
          getUserId(), classPK, destinationContainerModelId, serviceContext);
    } else {
      trashHandler.moveEntry(getUserId(), classPK, destinationContainerModelId, serviceContext);
    }
  }
  @Test
  public void testRestorePageWithParentPageInTrash() throws Exception {
    WikiPage[] pages =
        WikiTestUtil.addTrashedPageWithChildPage(group.getGroupId(), _node.getNodeId(), false);

    WikiPage childPage = pages[1];

    WikiPage newParentPage = WikiTestUtil.addPage(group.getGroupId(), _node.getNodeId(), true);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(getBaseModelClassName());

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    trashHandler.moveEntry(
        TestPropsValues.getUserId(),
        childPage.getResourcePrimKey(),
        newParentPage.getResourcePrimKey(),
        serviceContext);

    childPage = WikiPageLocalServiceUtil.getPage(childPage.getResourcePrimKey());

    Assert.assertTrue(childPage.isApproved());
    Assert.assertEquals(newParentPage.getTitle(), childPage.getParentTitle());
  }