示例#1
0
  @Override
  public boolean hasWorkflowDefinitionLink(
      long companyId, long groupId, long folderId, long fileEntryTypeId) throws Exception {

    while (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      DLFolder dlFolder = DLFolderLocalServiceUtil.fetchDLFolder(folderId);

      if (dlFolder == null) {
        return false;
      }

      if (dlFolder.isOverrideFileEntryTypes()) {
        break;
      }

      folderId = dlFolder.getParentFolderId();
    }

    if (WorkflowDefinitionLinkLocalServiceUtil.hasWorkflowDefinitionLink(
            companyId, groupId, DLFolderConstants.getClassName(), folderId, fileEntryTypeId)
        || WorkflowDefinitionLinkLocalServiceUtil.hasWorkflowDefinitionLink(
            companyId,
            groupId,
            DLFolderConstants.getClassName(),
            folderId,
            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL)) {

      return true;
    }

    return false;
  }
  public void restoreFolderFromTrash(long userId, Folder folder)
      throws PortalException, SystemException {

    // Folder

    TrashEntry trashEntry =
        trashEntryLocalService.getEntry(DLFolderConstants.getClassName(), folder.getFolderId());

    DLFolder dlFolder =
        dlFolderLocalService.updateStatus(
            userId,
            folder.getFolderId(),
            WorkflowConstants.STATUS_APPROVED,
            new HashMap<String, Serializable>(),
            new ServiceContext());

    dlFolder.setName(DLAppUtil.stripTrashNamespace(dlFolder.getName()));

    dlFolderPersistence.update(dlFolder, false);

    // File rank

    dlFileRankLocalService.enableFileRanksByFolderId(folder.getFolderId());

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
  }
  public Folder moveFolderToTrash(long userId, Folder folder)
      throws PortalException, SystemException {

    // Folder

    DLFolder dlFolder =
        dlFolderLocalService.updateStatus(
            userId,
            folder.getFolderId(),
            WorkflowConstants.STATUS_IN_TRASH,
            new HashMap<String, Serializable>(),
            new ServiceContext());

    dlFolder.setName(DLAppUtil.appendTrashNamespace(dlFolder.getName()));

    dlFolderPersistence.update(dlFolder, false);

    // File rank

    dlFileRankLocalService.disableFileRanksByFolderId(folder.getFolderId());

    // Trash

    trashEntryLocalService.addTrashEntry(
        userId,
        folder.getGroupId(),
        DLFolderConstants.getClassName(),
        folder.getFolderId(),
        WorkflowConstants.STATUS_APPROVED,
        null,
        null);

    return new LiferayFolder(dlFolder);
  }
  @Override
  public SyncDLObjectUpdate getSyncDLObjectUpdate(
      long companyId, long repositoryId, long parentFolderId, long lastAccessTime)
      throws PortalException {

    try {
      SyncUtil.checkSyncEnabled(repositoryId);

      repositoryService.checkRepository(repositoryId);

      List<SyncDLObject> syncDLObjects = new ArrayList<>();

      if (parentFolderId > 0) {
        PermissionChecker permissionChecker = getPermissionChecker();

        if (permissionChecker.hasPermission(
            repositoryId, DLFolderConstants.getClassName(), parentFolderId, ActionKeys.VIEW)) {

          SyncDLObject syncDLObject =
              syncDLObjectPersistence.fetchByT_T(SyncConstants.TYPE_FOLDER, parentFolderId);

          if (syncDLObject != null) {
            syncDLObjects.add(syncDLObject);
          }
        }
      }

      syncDLObjects =
          getSyncDLObjects(syncDLObjects, companyId, repositoryId, parentFolderId, lastAccessTime);

      return new SyncDLObjectUpdate(syncDLObjects, lastAccessTime);
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
  @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());
  }
  public void deleteFolder(Folder folder) throws PortalException, SystemException {

    // Sync

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.updateSync(
          folder.getFolderId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.EVENT_DELETE,
          "-1");
    }

    // Trash

    if (folder.getModel() instanceof DLFolder) {
      trashEntryLocalService.deleteEntry(DLFolderConstants.getClassName(), folder.getFolderId());
    }
  }
  @Override
  public SyncDLObject moveFolderToTrash(long folderId) throws PortalException {

    try {
      Folder folder = dlAppLocalService.getFolder(folderId);

      SyncUtil.checkSyncEnabled(folder.getGroupId());

      if (TrashUtil.isInTrash(DLFolderConstants.getClassName(), folderId)) {

        return null;
      }

      folder = dlAppService.moveFolderToTrash(folderId);

      return toSyncDLObject(folder, SyncConstants.EVENT_TRASH);
    } catch (NoSuchFolderException nsfe) {
      return null;
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
  public DLFolder updateStatus(
      long userId,
      long folderId,
      int status,
      Map<String, Serializable> workflowContext,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Folder

    User user = userPersistence.findByPrimaryKey(userId);

    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);

    int oldStatus = dlFolder.getStatus();

    dlFolder.setStatus(status);
    dlFolder.setStatusByUserId(user.getUserId());
    dlFolder.setStatusByUserName(user.getFullName());
    dlFolder.setStatusDate(new Date());

    dlFolderPersistence.update(dlFolder);

    // Folders, file entries, and file shortcuts

    QueryDefinition queryDefinition = new QueryDefinition(WorkflowConstants.STATUS_ANY);

    List<Object> foldersAndFileEntriesAndFileShortcuts =
        getFoldersAndFileEntriesAndFileShortcuts(
            dlFolder.getGroupId(), folderId, null, false, queryDefinition);

    dlAppHelperLocalService.updateDependentStatus(
        user, foldersAndFileEntriesAndFileShortcuts, status);

    // Asset

    if (status == WorkflowConstants.STATUS_APPROVED) {
      assetEntryLocalService.updateVisible(DLFolder.class.getName(), dlFolder.getFolderId(), true);
    } else if (status == WorkflowConstants.STATUS_IN_TRASH) {
      assetEntryLocalService.updateVisible(DLFolder.class.getName(), dlFolder.getFolderId(), false);
    }

    // Trash

    if (status == WorkflowConstants.STATUS_IN_TRASH) {
      UnicodeProperties typeSettingsProperties = new UnicodeProperties();

      typeSettingsProperties.put("title", dlFolder.getName());

      trashEntryLocalService.addTrashEntry(
          userId,
          dlFolder.getGroupId(),
          DLFolderConstants.getClassName(),
          dlFolder.getFolderId(),
          WorkflowConstants.STATUS_APPROVED,
          null,
          typeSettingsProperties);
    } else {
      trashEntryLocalService.deleteEntry(DLFolderConstants.getClassName(), dlFolder.getFolderId());
    }

    // Indexer

    if (((status == WorkflowConstants.STATUS_APPROVED)
            || (status == WorkflowConstants.STATUS_IN_TRASH)
            || (oldStatus == WorkflowConstants.STATUS_IN_TRASH))
        && ((serviceContext == null) || serviceContext.isIndexingEnabled())) {

      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(DLFolderConstants.getClassName());

      indexer.reindex(dlFolder);
    }

    return dlFolder;
  }
  public DLFolder addFolder(
      long userId,
      long groupId,
      long repositoryId,
      boolean mountPoint,
      long parentFolderId,
      String name,
      String description,
      boolean hidden,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Folder

    User user = userPersistence.findByPrimaryKey(userId);
    parentFolderId = getParentFolderId(groupId, parentFolderId);
    Date now = new Date();

    validateFolder(groupId, parentFolderId, name);

    long folderId = counterLocalService.increment();

    DLFolder dlFolder = dlFolderPersistence.create(folderId);

    dlFolder.setUuid(serviceContext.getUuid());
    dlFolder.setGroupId(groupId);
    dlFolder.setCompanyId(user.getCompanyId());
    dlFolder.setUserId(user.getUserId());
    dlFolder.setCreateDate(serviceContext.getCreateDate(now));
    dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
    dlFolder.setRepositoryId(repositoryId);
    dlFolder.setMountPoint(mountPoint);
    dlFolder.setParentFolderId(parentFolderId);
    dlFolder.setName(name);
    dlFolder.setDescription(description);
    dlFolder.setHidden(hidden);
    dlFolder.setOverrideFileEntryTypes(false);
    dlFolder.setExpandoBridgeAttributes(serviceContext);

    dlFolderPersistence.update(dlFolder);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addFolderResources(
          dlFolder, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      if (serviceContext.isDeriveDefaultPermissions()) {
        serviceContext.deriveDefaultPermissions(repositoryId, DLFolderConstants.getClassName());
      }

      addFolderResources(
          dlFolder, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Parent folder

    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(parentFolderId);

      parentDLFolder.setLastPostDate(now);

      dlFolderPersistence.update(parentDLFolder);
    }

    // App helper

    dlAppHelperLocalService.addFolder(userId, new LiferayFolder(dlFolder), serviceContext);

    return dlFolder;
  }