@Test
  public void testUpdateAssetWhenUpdatingFileEntry() throws Throwable {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    FileEntry fileEntry =
        DLAppLocalServiceUtil.addFileEntry(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(),
            ContentTypes.TEXT_PLAIN,
            "Old Title",
            RandomTestUtil.randomString(),
            null,
            RandomTestUtil.randomBytes(),
            serviceContext);

    DLAppLocalServiceUtil.updateFileEntry(
        TestPropsValues.getUserId(),
        fileEntry.getFileEntryId(),
        RandomTestUtil.randomString(),
        ContentTypes.TEXT_PLAIN,
        "New Title",
        RandomTestUtil.randomString(),
        null,
        true,
        RandomTestUtil.randomBytes(),
        serviceContext);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    Assert.assertEquals("New Title", assetEntry.getTitle());
  }
  private static void _checkFileEntry(String[] pathArray) throws Exception {
    if (pathArray.length == 1) {
      long dlFileShortcutId = GetterUtil.getLong(pathArray[0]);

      DLFileShortcut dlFileShortcut = DLAppLocalServiceUtil.getFileShortcut(dlFileShortcutId);

      DLAppLocalServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());
    } else if (pathArray.length == 2) {

      // Unable to check with UUID because of multiple repositories

    } else if (pathArray.length == 3) {
      long groupId = GetterUtil.getLong(pathArray[0]);
      long folderId = GetterUtil.getLong(pathArray[1]);
      String fileName = pathArray[2];

      try {
        DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);
      } catch (RepositoryException re) {
      }
    } else {
      long groupId = GetterUtil.getLong(pathArray[0]);

      String uuid = pathArray[3];

      try {
        DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
      } catch (RepositoryException re) {
      }
    }
  }
Esempio n. 3
0
  @Override
  public String getAbsolutePath(PortletRequest portletRequest, long folderId)
      throws PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return themeDisplay.translate("home");
    }

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    List<Folder> folders = folder.getAncestors();

    Collections.reverse(folders);

    StringBundler sb = new StringBundler((folders.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (Folder curFolder : folders) {
      sb.append(StringPool.RAQUO);
      sb.append(StringPool.SPACE);
      sb.append(curFolder.getName());
    }

    sb.append(StringPool.RAQUO);
    sb.append(StringPool.SPACE);
    sb.append(folder.getName());

    return sb.toString();
  }
Esempio n. 4
0
  @Override
  public boolean isSubscribedToFolder(
      long companyId, long groupId, long userId, long folderId, boolean recursive)
      throws PortalException, SystemException {

    List<Long> ancestorFolderIds = new ArrayList<Long>();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

      if (recursive) {
        ancestorFolderIds = folder.getAncestorFolderIds();

        ancestorFolderIds.add(groupId);
      }

      ancestorFolderIds.add(0, folderId);
    } else {
      ancestorFolderIds.add(groupId);
    }

    long[] folderIdsArray = ArrayUtil.toLongArray(ancestorFolderIds);

    return SubscriptionLocalServiceUtil.isSubscribed(
        companyId, userId, Folder.class.getName(), folderIdsArray);
  }
  protected String getBody(String className, long classPK, ServiceContext serviceContext)
      throws Exception {

    StringBundler sb = new StringBundler(11);

    sb.append("<div class=\"activity-body document\">");
    sb.append("<span class=\"document-thumbnail\"><img src=\"");

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    FileVersion fileVersion = fileEntry.getFileVersion();

    String thumbnailSrc =
        DLUtil.getThumbnailSrc(fileEntry, fileVersion, null, serviceContext.getThemeDisplay());

    sb.append(thumbnailSrc);
    sb.append("\"></span>");
    sb.append("<div class=\"document-container\"><div class=\"title\">");
    sb.append(getPageTitle(className, classPK, serviceContext));
    sb.append("</div><div class=\"version\">");
    sb.append(serviceContext.translate("version-x", fileVersion.getVersion()));
    sb.append("</div><div class=\"document-content\">");

    AssetRenderer assetRenderer = getAssetRenderer(className, classPK);

    sb.append(StringUtil.shorten(assetRenderer.getSummary(serviceContext.getLocale()), 200));

    sb.append("</div></div></div>");

    return sb.toString();
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Repository repository)
      throws Exception {

    Element repositoryElement = portletDataContext.getExportDataElement(repository);

    Folder folder = DLAppLocalServiceUtil.getFolder(repository.getDlFolderId());

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

      repositoryElement.addAttribute("hidden", String.valueOf(dlFolder.isHidden()));
    }

    portletDataContext.addClassedModel(
        repositoryElement, ExportImportPathUtil.getModelPath(repository), repository);

    List<RepositoryEntry> repositoryEntries =
        RepositoryEntryLocalServiceUtil.getRepositoryEntries(repository.getRepositoryId());

    for (RepositoryEntry repositoryEntry : repositoryEntries) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, repository, repositoryEntry, PortletDataContext.REFERENCE_TYPE_CHILD);
    }
  }
  @Before
  public void setUp() throws Exception {
    SimpleAction simpleAction = new AddDefaultDocumentLibraryStructuresAction();

    String companyIdString = String.valueOf(TestPropsValues.getCompanyId());

    simpleAction.run(new String[] {companyIdString});

    _group = GroupTestUtil.addGroup();

    _folder =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Folder A",
            "",
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    _subfolder =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            _folder.getFolderId(),
            "SubFolder AA",
            "",
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    _basicDocumentDLFileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(
            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);

    _dlFileEntryTypes =
        DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId()));

    for (DLFileEntryType dlFileEntryType : _dlFileEntryTypes) {
      String name = dlFileEntryType.getName(LocaleUtil.getSiteDefault());

      if (name.equals(DLFileEntryTypeConstants.NAME_CONTRACT)) {
        _contractDLFileEntryType = dlFileEntryType;
      } else if (name.equals(DLFileEntryTypeConstants.NAME_MARKETING_BANNER)) {

        _marketingBannerDLFileEntryType = dlFileEntryType;
      }
    }
  }
  @Override
  public boolean isVisible(long classPK, int status) throws Exception {
    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    FileVersion fileVersion = fileEntry.getFileVersion();

    return isVisible(fileVersion.getStatus(), status);
  }
 @Override
 public Folder getFolder() {
   try {
     return DLAppLocalServiceUtil.getFolder(_folderId);
   } catch (PortalException pe) {
     return null;
   }
 }
  @Override
  public void deletePortletFileEntry(long groupId, long folderId, String fileName)
      throws PortalException, SystemException {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);

    deletePortletFileEntry(fileEntry.getFileEntryId());
  }
  @Override
  public FileEntry fetchStagedModelByUuidAndGroupId(String uuid, long groupId) {

    try {
      return DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    } catch (PortalException pe) {
      return null;
    }
  }
  @Override
  public void restorePortletFileEntryFromTrash(
      long groupId, long userId, long folderId, String fileName)
      throws PortalException, SystemException {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);

    restorePortletFileEntryFromTrash(userId, fileEntry.getFileEntryId());
  }
  @Override
  public FileEntry addPortletFileEntry(
      long groupId,
      long userId,
      String className,
      long classPK,
      String portletId,
      long folderId,
      File file,
      String fileName,
      String mimeType,
      boolean indexingEnabled)
      throws PortalException, SystemException {

    if (Validator.isNull(fileName)) {
      return null;
    }

    ServiceContext serviceContext = new ServiceContext();

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

    Repository repository = addPortletRepository(groupId, portletId, serviceContext);

    serviceContext.setAttribute("className", className);
    serviceContext.setAttribute("classPK", String.valueOf(classPK));
    serviceContext.setIndexingEnabled(indexingEnabled);

    if (Validator.isNull(mimeType) || mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {

      mimeType = MimeTypesUtil.getContentType(file, fileName);
    }

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      return DLAppLocalServiceUtil.addFileEntry(
          userId,
          repository.getRepositoryId(),
          folderId,
          fileName,
          mimeType,
          fileName,
          StringPool.BLANK,
          StringPool.BLANK,
          file,
          serviceContext);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
Esempio n. 14
0
  public static void addPortletBreadcrumbEntries(
      long folderId, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return;
    }

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    addPortletBreadcrumbEntries(folder, request, renderResponse);
  }
  public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
      throws PortalException, SystemException {

    for (long classPK : classPKs) {
      if (checkPermission) {
        DLAppServiceUtil.deleteFileShortcut(classPK);
      } else {
        DLAppLocalServiceUtil.deleteFileShortcut(classPK);
      }
    }
  }
  public static boolean contains(
      PermissionChecker permissionChecker, long groupId, long folderId, String actionId)
      throws PortalException, SystemException {

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return DLPermission.contains(permissionChecker, groupId, actionId);
    } else {
      Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

      return folder.containsPermission(permissionChecker, actionId);
    }
  }
  @Test
  public void testGetFieldsFromContentWithDocumentLibraryElement() throws Exception {

    Fields expectedFields = new Fields();

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(group.getGroupId(), TestPropsValues.getUserId());

    FileEntry fileEntry =
        DLAppLocalServiceUtil.addFileEntry(
            TestPropsValues.getUserId(),
            group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Test 1.txt",
            ContentTypes.TEXT_PLAIN,
            RandomTestUtil.randomBytes(),
            serviceContext);

    Field documentLibraryField = getDocumentLibraryField(fileEntry, _ddmStructure.getStructureId());

    expectedFields.put(documentLibraryField);

    Field fieldsDisplayField =
        getFieldsDisplayField(_ddmStructure.getStructureId(), "document_library_INSTANCE_4aGOvP3N");

    expectedFields.put(fieldsDisplayField);

    String content = read("test-journal-content-doc-library-field.xml");

    XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-content");

    Document document = SAXReaderUtil.read(content);

    Element element = (Element) xPathSelector.selectSingleNode(document);

    String[] previewURLs = new String[2];

    previewURLs[0] =
        DLUtil.getPreviewURL(
            fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, true, true);
    previewURLs[1] =
        DLUtil.getPreviewURL(
            fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, false);

    for (int i = 0; i < previewURLs.length; i++) {
      element.addCDATA(previewURLs[i]);

      Fields actualFields = JournalConverterUtil.getDDMFields(_ddmStructure, document.asXML());

      Assert.assertEquals(expectedFields, actualFields);
    }
  }
  @Override
  public void deletePortletFileEntry(long fileEntryId) throws PortalException, SystemException {

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      DLAppLocalServiceUtil.deleteFileEntry(fileEntryId);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
  @Override
  public Folder addPortletFolder(
      long userId,
      long repositoryId,
      long parentFolderId,
      String folderName,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      return DLAppLocalServiceUtil.getFolder(repositoryId, parentFolderId, folderName);
    } catch (NoSuchFolderException nsfe) {
      return DLAppLocalServiceUtil.addFolder(
          userId, repositoryId, parentFolderId, folderName, StringPool.BLANK, serviceContext);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
  protected DLFileRank addDLFileRank(long fileEntryId) throws Exception {
    ServiceContext serviceContext = new ServiceContext();

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

    return DLAppLocalServiceUtil.addFileRank(
        TestPropsValues.getGroupId(),
        TestPropsValues.getCompanyId(),
        TestPropsValues.getUserId(),
        fileEntryId,
        serviceContext);
  }
  @Override
  public FileEntry fetchStagedModelByUuidAndGroupId(String uuid, long groupId) {

    try {
      return DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    } catch (PortalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug(pe, pe);
      }

      return null;
    }
  }
  protected Folder addFolder(long parentFolderId, String name, boolean deleteExisting)
      throws Exception {

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

    if (deleteExisting) {
      try {
        Folder folder = DLAppLocalServiceUtil.getFolder(_group.getGroupId(), parentFolderId, name);

        DLAppLocalServiceUtil.deleteFolder(folder.getFolderId());
      } catch (NoSuchFolderException nsfe) {
      }
    }

    return DLAppLocalServiceUtil.addFolder(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        parentFolderId,
        name,
        StringPool.BLANK,
        serviceContext);
  }
  @Override
  public void restorePortletFileEntryFromTrash(long userId, long fileEntryId)
      throws PortalException, SystemException {

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      DLAppLocalServiceUtil.restoreFileEntryFromTrash(userId, fileEntryId);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
  @Override
  public FileEntry movePortletFileEntryToTrash(long userId, long fileEntryId)
      throws PortalException, SystemException {

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      return DLAppLocalServiceUtil.moveFileEntryToTrash(userId, fileEntryId);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
  protected FileEntry addFileEntry(long folderId, String sourceFileName) throws Exception {

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(group.getGroupId(), TestPropsValues.getUserId());

    return DLAppLocalServiceUtil.addFileEntry(
        TestPropsValues.getUserId(),
        group.getGroupId(),
        folderId,
        sourceFileName,
        ContentTypes.TEXT_PLAIN,
        RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE),
        serviceContext);
  }
Esempio n. 26
0
  @Override
  public List<Object> getEntries(Hits hits) {
    List<Object> entries = new ArrayList<Object>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        Object obj = null;

        if (entryClassName.equals(DLFileEntry.class.getName())) {
          obj = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
        } else if (entryClassName.equals(MBMessage.class.getName())) {
          long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));

          DLAppLocalServiceUtil.getFileEntry(classPK);

          obj = MBMessageLocalServiceUtil.getMessage(entryClassPK);
        }

        entries.add(obj);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Documents and Media search index is stale and "
                  + "contains entry {className="
                  + entryClassName
                  + ", classPK="
                  + entryClassPK
                  + "}");
        }
      }
    }

    return entries;
  }
  @Override
  public AssetRenderer getAssetRenderer(long classPK, int type)
      throws PortalException, SystemException {

    FileEntry fileEntry = null;
    FileVersion fileVersion = null;

    if (type == TYPE_LATEST) {
      fileVersion = DLAppLocalServiceUtil.getFileVersion(classPK);

      fileEntry = fileVersion.getFileEntry();
    } else {
      fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

      fileVersion = fileEntry.getFileVersion();
    }

    DLFileEntryAssetRenderer dlFileEntryAssetRenderer =
        new DLFileEntryAssetRenderer(fileEntry, fileVersion);

    dlFileEntryAssetRenderer.setAssetRendererType(type);

    return dlFileEntryAssetRenderer;
  }
  @Override
  public boolean isVisibleRelatedEntry(long classPK, int status) throws Exception {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    if (fileEntry instanceof LiferayFileEntry) {
      DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

      if (dlFileEntry.isInHiddenFolder()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(dlFileEntry.getClassName());

        return indexer.isVisible(dlFileEntry.getClassPK(), status);
      }
    }

    return true;
  }
  /** @see com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter */
  public static boolean hasFiles(HttpServletRequest request) {
    try {

      // Do not use permission checking since this may be called from
      // other contexts that are also managing the principal

      User user = _getUser(request);

      String path = HttpUtil.fixPath(request.getPathInfo());

      String[] pathArray = StringUtil.split(path, CharPool.SLASH);

      if (pathArray.length == 0) {
        return true;
      } else if (_PATH_DDM.equals(pathArray[0])) {
        _checkDDMRecord(pathArray);
      } else if (Validator.isNumber(pathArray[0])) {
        _checkFileEntry(pathArray);
      } else {
        long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

        for (int i = 1; i < pathArray.length; i++) {
          try {
            Folder folder = DLAppLocalServiceUtil.getFolder(groupId, folderId, pathArray[i]);

            folderId = folder.getFolderId();
          } catch (NoSuchFolderException nsfe) {
            if (i != (pathArray.length - 1)) {
              return false;
            }

            pathArray =
                new String[] {String.valueOf(groupId), String.valueOf(folderId), pathArray[i]};

            _checkFileEntry(pathArray);
          }
        }
      }
    } catch (Exception e) {
      return false;
    }

    return true;
  }
  @Test
  public void testUpdateAssetWhenUpdatingFolder() throws Throwable {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    Folder folder = addFolder(false, "Old Name");

    DLAppLocalServiceUtil.updateFolder(
        folder.getFolderId(),
        folder.getParentFolderId(),
        "New Name",
        RandomTestUtil.randomString(),
        serviceContext);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(DLFolderConstants.getClassName(), folder.getFolderId());

    Assert.assertEquals("New Name", assetEntry.getTitle());
  }