コード例 #1
0
  public DLFileShortcut addFileShortcut(
      String uuid,
      long userId,
      long folderId,
      long toFolderId,
      String toName,
      Boolean addCommunityPermissions,
      Boolean addGuestPermissions,
      String[] communityPermissions,
      String[] guestPermissions)
      throws PortalException, SystemException {

    // File shortcut

    User user = userPersistence.findByPrimaryKey(userId);
    folderId = getFolderId(user.getCompanyId(), folderId);
    DLFolder folder = dlFolderPersistence.findByPrimaryKey(folderId);
    Date now = new Date();

    validate(user, toFolderId, toName);

    long fileShortcutId = counterLocalService.increment();

    DLFileShortcut fileShortcut = dlFileShortcutPersistence.create(fileShortcutId);

    fileShortcut.setUuid(uuid);
    fileShortcut.setCompanyId(user.getCompanyId());
    fileShortcut.setUserId(user.getUserId());
    fileShortcut.setUserName(user.getFullName());
    fileShortcut.setCreateDate(now);
    fileShortcut.setModifiedDate(now);
    fileShortcut.setFolderId(folderId);
    fileShortcut.setToFolderId(toFolderId);
    fileShortcut.setToName(toName);

    dlFileShortcutPersistence.update(fileShortcut);

    // Resources

    if ((addCommunityPermissions != null) && (addGuestPermissions != null)) {

      addFileShortcutResources(
          folder,
          fileShortcut,
          addCommunityPermissions.booleanValue(),
          addGuestPermissions.booleanValue());
    } else {
      addFileShortcutResources(folder, fileShortcut, communityPermissions, guestPermissions);
    }

    // Folder

    folder.setLastPostDate(fileShortcut.getModifiedDate());

    dlFolderPersistence.update(folder);

    return fileShortcut;
  }
  protected DLFileShortcut addDLFileShortcut() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DLFileShortcut dlFileShortcut = _persistence.create(pk);

    dlFileShortcut.setUuid(RandomTestUtil.randomString());

    dlFileShortcut.setGroupId(RandomTestUtil.nextLong());

    dlFileShortcut.setCompanyId(RandomTestUtil.nextLong());

    dlFileShortcut.setUserId(RandomTestUtil.nextLong());

    dlFileShortcut.setUserName(RandomTestUtil.randomString());

    dlFileShortcut.setCreateDate(RandomTestUtil.nextDate());

    dlFileShortcut.setModifiedDate(RandomTestUtil.nextDate());

    dlFileShortcut.setRepositoryId(RandomTestUtil.nextLong());

    dlFileShortcut.setFolderId(RandomTestUtil.nextLong());

    dlFileShortcut.setToFileEntryId(RandomTestUtil.nextLong());

    dlFileShortcut.setTreePath(RandomTestUtil.randomString());

    dlFileShortcut.setActive(RandomTestUtil.randomBoolean());

    dlFileShortcut.setStatus(RandomTestUtil.nextInt());

    dlFileShortcut.setStatusByUserId(RandomTestUtil.nextLong());

    dlFileShortcut.setStatusByUserName(RandomTestUtil.randomString());

    dlFileShortcut.setStatusDate(RandomTestUtil.nextDate());

    _dlFileShortcuts.add(_persistence.update(dlFileShortcut));

    return dlFileShortcut;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DLFileShortcut newDLFileShortcut = _persistence.create(pk);

    newDLFileShortcut.setUuid(RandomTestUtil.randomString());

    newDLFileShortcut.setGroupId(RandomTestUtil.nextLong());

    newDLFileShortcut.setCompanyId(RandomTestUtil.nextLong());

    newDLFileShortcut.setUserId(RandomTestUtil.nextLong());

    newDLFileShortcut.setUserName(RandomTestUtil.randomString());

    newDLFileShortcut.setCreateDate(RandomTestUtil.nextDate());

    newDLFileShortcut.setModifiedDate(RandomTestUtil.nextDate());

    newDLFileShortcut.setRepositoryId(RandomTestUtil.nextLong());

    newDLFileShortcut.setFolderId(RandomTestUtil.nextLong());

    newDLFileShortcut.setToFileEntryId(RandomTestUtil.nextLong());

    newDLFileShortcut.setTreePath(RandomTestUtil.randomString());

    newDLFileShortcut.setActive(RandomTestUtil.randomBoolean());

    newDLFileShortcut.setStatus(RandomTestUtil.nextInt());

    newDLFileShortcut.setStatusByUserId(RandomTestUtil.nextLong());

    newDLFileShortcut.setStatusByUserName(RandomTestUtil.randomString());

    newDLFileShortcut.setStatusDate(RandomTestUtil.nextDate());

    _dlFileShortcuts.add(_persistence.update(newDLFileShortcut));

    DLFileShortcut existingDLFileShortcut =
        _persistence.findByPrimaryKey(newDLFileShortcut.getPrimaryKey());

    Assert.assertEquals(existingDLFileShortcut.getUuid(), newDLFileShortcut.getUuid());
    Assert.assertEquals(
        existingDLFileShortcut.getFileShortcutId(), newDLFileShortcut.getFileShortcutId());
    Assert.assertEquals(existingDLFileShortcut.getGroupId(), newDLFileShortcut.getGroupId());
    Assert.assertEquals(existingDLFileShortcut.getCompanyId(), newDLFileShortcut.getCompanyId());
    Assert.assertEquals(existingDLFileShortcut.getUserId(), newDLFileShortcut.getUserId());
    Assert.assertEquals(existingDLFileShortcut.getUserName(), newDLFileShortcut.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFileShortcut.getCreateDate()),
        Time.getShortTimestamp(newDLFileShortcut.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFileShortcut.getModifiedDate()),
        Time.getShortTimestamp(newDLFileShortcut.getModifiedDate()));
    Assert.assertEquals(
        existingDLFileShortcut.getRepositoryId(), newDLFileShortcut.getRepositoryId());
    Assert.assertEquals(existingDLFileShortcut.getFolderId(), newDLFileShortcut.getFolderId());
    Assert.assertEquals(
        existingDLFileShortcut.getToFileEntryId(), newDLFileShortcut.getToFileEntryId());
    Assert.assertEquals(existingDLFileShortcut.getTreePath(), newDLFileShortcut.getTreePath());
    Assert.assertEquals(existingDLFileShortcut.getActive(), newDLFileShortcut.getActive());
    Assert.assertEquals(existingDLFileShortcut.getStatus(), newDLFileShortcut.getStatus());
    Assert.assertEquals(
        existingDLFileShortcut.getStatusByUserId(), newDLFileShortcut.getStatusByUserId());
    Assert.assertEquals(
        existingDLFileShortcut.getStatusByUserName(), newDLFileShortcut.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFileShortcut.getStatusDate()),
        Time.getShortTimestamp(newDLFileShortcut.getStatusDate()));
  }