コード例 #1
0
  @Test
  public void testArticleImages() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    int initialArticleImagesCount =
        JournalArticleImageLocalServiceUtil.getArticleImagesCount(group.getGroupId());

    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    String definition =
        StringUtil.read(
            classLoader,
            "com/liferay/journal/dependencies" + "/test-ddm-structure-image-field.xml");

    DDMForm ddmForm = DDMFormXSDDeserializerUtil.deserialize(definition);

    DDMStructure ddmStructure =
        DDMStructureTestUtil.addStructure(
            serviceContext.getScopeGroupId(), JournalArticle.class.getName(), ddmForm);

    DDMTemplate ddmTemplate =
        DDMTemplateTestUtil.addTemplate(
            serviceContext.getScopeGroupId(), ddmStructure.getStructureId());

    String content =
        StringUtil.read(
            classLoader,
            "com/liferay/journal/dependencies" + "/test-journal-content-image-field.xml");

    Map<String, byte[]> images = new HashMap<>();

    images.put(
        "_image_1_0_en_US",
        FileUtil.getBytes(clazz, "/com/liferay/journal/dependencies/liferay.png"));

    baseModel =
        JournalTestUtil.addArticleWithXMLContent(
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            content,
            ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey(),
            images,
            serviceContext);

    Assert.assertEquals(
        initialArticleImagesCount + 1,
        JournalArticleImageLocalServiceUtil.getArticleImagesCount(group.getGroupId()));

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

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

    trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));

    Assert.assertEquals(
        initialArticleImagesCount,
        JournalArticleImageLocalServiceUtil.getArticleImagesCount(group.getGroupId()));
  }
コード例 #2
0
  protected void deleteEntry(TrashEntry entry) throws PortalException {
    PermissionChecker permissionChecker = getPermissionChecker();

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName());

    if (!trashHandler.hasTrashPermission(
        permissionChecker, 0, entry.getClassPK(), ActionKeys.DELETE)) {

      throw new TrashPermissionException(TrashPermissionException.DELETE);
    }

    trashHandler.deleteTrashEntry(entry.getClassPK());
  }
コード例 #3
0
  /**
   * Restores the trash entry to its original location. In order to handle a duplicate trash entry
   * already existing at the original location, either pass in the primary key of the existing trash
   * entry's entity to overwrite or pass in a new name to give to the trash entry being restored.
   *
   * <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#RESTORE} - if the user did not have permission to restore
   *       the trash entry
   *   <li>{@link TrashPermissionException#RESTORE_OVERWRITE} - if the user did not have permission
   *       to delete the existing trash entry
   *   <li>{@link TrashPermissionException#RESTORE_RENAME} - if the user did not have permission to
   *       rename the trash entry
   * </ul>
   *
   * @param entryId the primary key of the trash entry to restore
   * @param overrideClassPK the primary key of the entity to overwrite (optionally <code>0</code>)
   * @param name a new name to give to the trash entry being restored (optionally <code>null</code>)
   * @return the restored trash entry
   * @throws PortalException if a matching trash entry could not be found, if the user did not have
   *     permission to overwrite an existing trash entry, to rename the trash entry being restored,
   *     or to restore the trash entry in general
   */
  @Override
  public TrashEntry restoreEntry(long entryId, long overrideClassPK, String name)
      throws PortalException {

    PermissionChecker permissionChecker = getPermissionChecker();

    TrashEntry entry = trashEntryPersistence.findByPrimaryKey(entryId);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName());

    if (!trashHandler.hasTrashPermission(
        permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RESTORE)) {

      throw new TrashPermissionException(TrashPermissionException.RESTORE);
    }

    if (overrideClassPK > 0) {
      if (!trashHandler.hasTrashPermission(
          permissionChecker, 0, overrideClassPK, TrashActionKeys.OVERWRITE)) {

        throw new TrashPermissionException(TrashPermissionException.RESTORE_OVERWRITE);
      }

      trashHandler.deleteTrashEntry(overrideClassPK);

      trashHandler.checkRestorableEntry(entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, null);
    } else if (name != null) {
      if (!trashHandler.hasTrashPermission(
          permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RENAME)) {

        throw new TrashPermissionException(TrashPermissionException.RESTORE_RENAME);
      }

      trashHandler.checkRestorableEntry(entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, name);

      trashHandler.updateTitle(entry.getClassPK(), name);
    }

    trashHandler.restoreTrashEntry(getUserId(), entry.getClassPK());

    return entry;
  }