Ejemplo n.º 1
0
  protected void updateFileShortcut(ActionRequest actionRequest) throws Exception {

    long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");

    long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");
    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    long toFileEntryId = ParamUtil.getLong(actionRequest, "toFileEntryId");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(DLFileShortcut.class.getName(), actionRequest);

    if (fileShortcutId <= 0) {

      // Add file shortcut

      DLFileShortcut fileShortcut =
          DLAppServiceUtil.addFileShortcut(repositoryId, folderId, toFileEntryId, serviceContext);

      AssetPublisherUtil.addAndStoreSelection(
          actionRequest, DLFileShortcut.class.getName(), fileShortcut.getFileShortcutId(), -1);
    } else {

      // Update file shortcut

      DLAppServiceUtil.updateFileShortcut(fileShortcutId, folderId, toFileEntryId, serviceContext);

      AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileShortcut.class.getName(), folderId);
    }
  }
  protected void trashFileEntry() throws Exception {
    Group group = ServiceTestUtil.addGroup();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setScopeGroupId(group.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    int initialBaseModelsCount = getBaseModelsNotInTrashCount(parentBaseModel);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    BaseModel<?> baseModel = addBaseModel(parentBaseModel, true, serviceContext);

    DLFileShortcut dlFileShortcut = (DLFileShortcut) baseModel;

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.restoreFileEntryFromTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
  }
  protected FileEntry getFileEntry(String[] pathArray) throws Exception {
    if (pathArray.length == 1) {
      long dlFileShortcutId = GetterUtil.getLong(pathArray[0]);

      DLFileShortcut dlFileShortcut = DLAppServiceUtil.getFileShortcut(dlFileShortcutId);

      return DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());
    } else if (pathArray.length == 2) {
      long groupId = GetterUtil.getLong(pathArray[0]);

      return DLAppServiceUtil.getFileEntryByUuidAndGroupId(pathArray[1], groupId);
    } else if (pathArray.length == 3) {
      long groupId = GetterUtil.getLong(pathArray[0]);
      long folderId = GetterUtil.getLong(pathArray[1]);

      String fileName = pathArray[2];

      if (fileName.contains(StringPool.QUESTION)) {
        fileName = fileName.substring(0, fileName.indexOf(StringPool.QUESTION));
      }

      return DLAppServiceUtil.getFileEntry(groupId, folderId, fileName);
    } else {
      long groupId = GetterUtil.getLong(pathArray[0]);

      String uuid = pathArray[3];

      return DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    }
  }
  @Override
  protected BaseModel<?> addBaseModel(
      BaseModel<?> parentBaseModel, boolean approved, ServiceContext serviceContext)
      throws Exception {

    DLFolder dlFolder = (DLFolder) parentBaseModel;

    String content = "Content: Enterprise. Open Source. For Life.";

    serviceContext = (ServiceContext) serviceContext.clone();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            dlFolder.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Text.txt",
            ContentTypes.TEXT_PLAIN,
            getSearchKeywords(),
            StringPool.BLANK,
            StringPool.BLANK,
            content.getBytes(),
            serviceContext);

    return DLAppServiceUtil.addFileShortcut(
        dlFolder.getGroupId(), dlFolder.getFolderId(), fileEntry.getFileEntryId(), serviceContext);
  }
Ejemplo n.º 5
0
  public static Folder getGadgetEditorRootFolder(long repositoryId) throws Exception {

    Folder folder = null;

    try {
      folder =
          DLAppServiceUtil.getFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME);
    } catch (Exception e) {
    }

    if (folder == null) {
      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setScopeGroupId(repositoryId);

      folder =
          DLAppServiceUtil.addFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME,
              StringPool.BLANK,
              serviceContext);
    }

    return folder;
  }
  @Override
  protected void addActivities() throws Exception {
    _folder =
        DLAppTestUtil.addFolder(
            group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            ServiceTestUtil.randomString());

    DLAppServiceUtil.moveFolderToTrash(_folder.getFolderId());

    DLAppServiceUtil.restoreFolderFromTrash(_folder.getFolderId());
  }
Ejemplo n.º 7
0
  protected void deleteFileShortcut(ActionRequest actionRequest, boolean moveToTrash)
      throws Exception {

    long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");

    if (moveToTrash) {
      DLFileShortcut fileShortcut = DLAppServiceUtil.moveFileShortcutToTrash(fileShortcutId);

      TrashUtil.addTrashSessionMessages(actionRequest, fileShortcut);

      hideDefaultSuccessMessage(actionRequest);
    } else {
      DLAppServiceUtil.deleteFileShortcut(fileShortcutId);
    }
  }
  protected String fileUpload(
      CommandArgument commandArgument, String fileName, File file, String extension) {

    try {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      long folderId = folder.getFolderId();
      String title = fileName;
      String description = StringPool.BLANK;
      String changeLog = StringPool.BLANK;

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      DLAppServiceUtil.addFileEntry(
          group.getGroupId(), folderId, title, description, changeLog, file, serviceContext);
    } catch (Exception e) {
      throw new FCKException(e);
    }

    return "0";
  }
  private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element foldersElement = document.createElement("Folders");

    rootNode.appendChild(foldersElement);

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      getRootFolders(commandArgument, document, foldersElement);
    } else {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId());

      for (Folder curFolder : folders) {
        Element folderElement = document.createElement("Folder");

        foldersElement.appendChild(folderElement);

        folderElement.setAttribute("name", curFolder.getName());
      }
    }
  }
  private Folder _getFolder(long groupId, String folderName) throws Exception {

    DLFolder dlFolder = new DLFolderImpl();

    dlFolder.setFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    dlFolder.setGroupId(groupId);

    Folder folder = new LiferayFolder(dlFolder);

    if (folderName.equals(StringPool.SLASH)) {
      return folder;
    }

    StringTokenizer st = new StringTokenizer(folderName, StringPool.SLASH);

    while (st.hasMoreTokens()) {
      String curFolderName = st.nextToken();

      List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folder.getFolderId());

      for (Folder curFolder : folders) {
        if (curFolder.getName().equals(curFolderName)) {
          folder = curFolder;

          break;
        }
      }
    }

    return folder;
  }
Ejemplo n.º 11
0
  public static void getFolder(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long folderId = ParamUtil.getLong(request, "folderId");

    Folder folder = null;

    if ((folderId > 0) && (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      folder = DLAppServiceUtil.getFolder(folderId);

      if (folder.getModel() instanceof DLFolder) {
        DLFolder dlFolder = (DLFolder) folder.getModel();

        if (dlFolder.isInTrash() || dlFolder.isInTrashContainer()) {
          throw new NoSuchFolderException();
        }
      }
    } else {
      DLPermission.check(
          themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW);
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder);
  }
 @Override
 protected void renameModels() throws Exception {
   DLAppServiceUtil.updateFolder(
       _folder.getFolderId(),
       ServiceTestUtil.randomString(),
       ServiceTestUtil.randomString(),
       serviceContext);
 }
  @Override
  public void moveEntry(long classPK, long containerModelId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    DLFileShortcut dlFileShortcut = getDLFileShortcut(classPK);

    DLAppServiceUtil.updateFileShortcut(
        classPK, containerModelId, dlFileShortcut.getToFileEntryId(), serviceContext);
  }
Ejemplo n.º 14
0
  public static void deleteFileShortcut(long fileShortcutId) throws RemoteException {
    try {
      DLAppServiceUtil.deleteFileShortcut(fileShortcutId);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 15
0
  public static void deleteFolder(long folderId) throws RemoteException {
    try {
      DLAppServiceUtil.deleteFolder(folderId);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 16
0
  public static void checkOutFileEntry(long fileEntryId) throws RemoteException {
    try {
      DLAppServiceUtil.checkOutFileEntry(fileEntryId);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 17
0
  protected void moveFileShortcut(ActionRequest actionRequest, boolean moveFromTrash)
      throws Exception {

    long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");

    long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId");

    DLFileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId);

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(DLFileShortcut.class.getName(), actionRequest);

    if (moveFromTrash) {
      DLAppServiceUtil.moveFileShortcutFromTrash(fileShortcutId, newFolderId, serviceContext);
    } else {
      DLAppServiceUtil.updateFileShortcut(
          fileShortcutId, newFolderId, fileShortcut.getToFileEntryId(), serviceContext);
    }
  }
Ejemplo n.º 18
0
  public static void checkInFileEntry(long fileEntryId, java.lang.String lockUuid)
      throws RemoteException {
    try {
      DLAppServiceUtil.checkInFileEntry(fileEntryId, lockUuid);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 19
0
  public static void unlockFolder(long repositoryId, long folderId, java.lang.String lockUuid)
      throws RemoteException {
    try {
      DLAppServiceUtil.unlockFolder(repositoryId, folderId, lockUuid);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 20
0
  public static void deleteFolder(long repositoryId, long parentFolderId, java.lang.String name)
      throws RemoteException {
    try {
      DLAppServiceUtil.deleteFolder(repositoryId, parentFolderId, name);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 21
0
  public static void deleteFileEntryByTitle(
      long repositoryId, long folderId, java.lang.String title) throws RemoteException {
    try {
      DLAppServiceUtil.deleteFileEntryByTitle(repositoryId, folderId, title);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
      throws PortalException, SystemException {

    for (long classPK : classPKs) {
      if (checkPermission) {
        DLAppServiceUtil.deleteFileShortcut(classPK);
      } else {
        DLAppLocalServiceUtil.deleteFileShortcut(classPK);
      }
    }
  }
Ejemplo n.º 23
0
  public static int getFoldersCount(long repositoryId, long parentFolderId) throws RemoteException {
    try {
      int returnValue = DLAppServiceUtil.getFoldersCount(repositoryId, parentFolderId);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 24
0
  public static void getFileShortcut(HttpServletRequest request) throws Exception {

    long fileShortcutId = ParamUtil.getLong(request, "fileShortcutId");

    DLFileShortcut fileShortcut = null;

    if (fileShortcutId > 0) {
      fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId);
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_SHORTCUT, fileShortcut);
  }
  protected void compareVersions(RenderRequest renderRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(renderRequest, "fileEntryId");

    String sourceVersion = ParamUtil.getString(renderRequest, "sourceVersion");
    String targetVersion = ParamUtil.getString(renderRequest, "targetVersion");

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

    String extension = fileEntry.getExtension();

    FileVersion sourceFileVersion = fileEntry.getFileVersion(sourceVersion);

    String sourceTitle = sourceFileVersion.getTitle();

    FileVersion targetFileVersion = fileEntry.getFileVersion(targetVersion);

    String targetTitle = targetFileVersion.getTitle();

    InputStream sourceIs = fileEntry.getContentStream(sourceVersion);
    InputStream targetIs = fileEntry.getContentStream(targetVersion);

    if (extension.equals("htm") || extension.equals("html") || extension.equals("xml")) {

      String escapedSource = HtmlUtil.escape(StringUtil.read(sourceIs));
      String escapedTarget = HtmlUtil.escape(StringUtil.read(targetIs));

      sourceIs = new UnsyncByteArrayInputStream(escapedSource.getBytes(StringPool.UTF8));
      targetIs = new UnsyncByteArrayInputStream(escapedTarget.getBytes(StringPool.UTF8));
    }

    if (DocumentConversionUtil.isEnabled()
        && DocumentConversionUtil.isConvertBeforeCompare(extension)) {

      String sourceTempFileId = DLUtil.getTempFileId(fileEntryId, sourceVersion);
      String targetTempFileId = DLUtil.getTempFileId(fileEntryId, targetVersion);

      sourceIs =
          new FileInputStream(
              DocumentConversionUtil.convert(sourceTempFileId, sourceIs, extension, "txt"));
      targetIs =
          new FileInputStream(
              DocumentConversionUtil.convert(targetTempFileId, targetIs, extension, "txt"));
    }

    List<DiffResult>[] diffResults =
        DiffUtil.diff(new InputStreamReader(sourceIs), new InputStreamReader(targetIs));

    renderRequest.setAttribute(WebKeys.SOURCE_NAME, sourceTitle + StringPool.SPACE + sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_NAME, targetTitle + StringPool.SPACE + targetVersion);
    renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
  }
Ejemplo n.º 26
0
  public static boolean verifyInheritableLock(
      long repositoryId, long folderId, java.lang.String lockUuid) throws RemoteException {
    try {
      boolean returnValue =
          DLAppServiceUtil.verifyInheritableLock(repositoryId, folderId, lockUuid);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 27
0
  public static void revertFileEntry(
      long fileEntryId,
      java.lang.String version,
      com.liferay.portal.service.ServiceContext serviceContext)
      throws RemoteException {
    try {
      DLAppServiceUtil.revertFileEntry(fileEntryId, version, serviceContext);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 28
0
  public static java.lang.Long[] getSubfolderIds(long repositoryId, long folderId, boolean recurse)
      throws RemoteException {
    try {
      java.util.List<java.lang.Long> returnValue =
          DLAppServiceUtil.getSubfolderIds(repositoryId, folderId, recurse);

      return returnValue.toArray(new java.lang.Long[returnValue.size()]);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 29
0
  public static java.util.List<com.liferay.portal.kernel.repository.model.Folder> getFolders(
      long repositoryId, long parentFolderId, int start, int end) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.kernel.repository.model.Folder> returnValue =
          DLAppServiceUtil.getFolders(repositoryId, parentFolderId, start, end);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Ejemplo n.º 30
0
  public static com.liferay.portlet.documentlibrary.model.DLFileShortcutSoap getFileShortcut(
      long fileShortcutId) throws RemoteException {
    try {
      com.liferay.portlet.documentlibrary.model.DLFileShortcut returnValue =
          DLAppServiceUtil.getFileShortcut(fileShortcutId);

      return com.liferay.portlet.documentlibrary.model.DLFileShortcutSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }