/**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static DLFolder toModel(DLFolderSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    DLFolder model = new DLFolderImpl();

    model.setUuid(soapModel.getUuid());
    model.setFolderId(soapModel.getFolderId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setRepositoryId(soapModel.getRepositoryId());
    model.setMountPoint(soapModel.getMountPoint());
    model.setParentFolderId(soapModel.getParentFolderId());
    model.setTreePath(soapModel.getTreePath());
    model.setName(soapModel.getName());
    model.setDescription(soapModel.getDescription());
    model.setLastPostDate(soapModel.getLastPostDate());
    model.setDefaultFileEntryTypeId(soapModel.getDefaultFileEntryTypeId());
    model.setHidden(soapModel.getHidden());
    model.setRestrictionType(soapModel.getRestrictionType());
    model.setLastPublishDate(soapModel.getLastPublishDate());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());

    return model;
  }
  protected DLFolder addDLFolder() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DLFolder dlFolder = _persistence.create(pk);

    dlFolder.setUuid(RandomTestUtil.randomString());

    dlFolder.setGroupId(RandomTestUtil.nextLong());

    dlFolder.setCompanyId(RandomTestUtil.nextLong());

    dlFolder.setUserId(RandomTestUtil.nextLong());

    dlFolder.setUserName(RandomTestUtil.randomString());

    dlFolder.setCreateDate(RandomTestUtil.nextDate());

    dlFolder.setModifiedDate(RandomTestUtil.nextDate());

    dlFolder.setRepositoryId(RandomTestUtil.nextLong());

    dlFolder.setMountPoint(RandomTestUtil.randomBoolean());

    dlFolder.setParentFolderId(RandomTestUtil.nextLong());

    dlFolder.setTreePath(RandomTestUtil.randomString());

    dlFolder.setName(RandomTestUtil.randomString());

    dlFolder.setDescription(RandomTestUtil.randomString());

    dlFolder.setLastPostDate(RandomTestUtil.nextDate());

    dlFolder.setDefaultFileEntryTypeId(RandomTestUtil.nextLong());

    dlFolder.setHidden(RandomTestUtil.randomBoolean());

    dlFolder.setOverrideFileEntryTypes(RandomTestUtil.randomBoolean());

    dlFolder.setStatus(RandomTestUtil.nextInt());

    dlFolder.setStatusByUserId(RandomTestUtil.nextLong());

    dlFolder.setStatusByUserName(RandomTestUtil.randomString());

    dlFolder.setStatusDate(RandomTestUtil.nextDate());

    _persistence.update(dlFolder);

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

    DLFolder newDLFolder = _persistence.create(pk);

    newDLFolder.setUuid(ServiceTestUtil.randomString());

    newDLFolder.setGroupId(ServiceTestUtil.nextLong());

    newDLFolder.setCompanyId(ServiceTestUtil.nextLong());

    newDLFolder.setUserId(ServiceTestUtil.nextLong());

    newDLFolder.setUserName(ServiceTestUtil.randomString());

    newDLFolder.setCreateDate(ServiceTestUtil.nextDate());

    newDLFolder.setModifiedDate(ServiceTestUtil.nextDate());

    newDLFolder.setRepositoryId(ServiceTestUtil.nextLong());

    newDLFolder.setMountPoint(ServiceTestUtil.randomBoolean());

    newDLFolder.setParentFolderId(ServiceTestUtil.nextLong());

    newDLFolder.setName(ServiceTestUtil.randomString());

    newDLFolder.setDescription(ServiceTestUtil.randomString());

    newDLFolder.setLastPostDate(ServiceTestUtil.nextDate());

    newDLFolder.setDefaultFileEntryTypeId(ServiceTestUtil.nextLong());

    newDLFolder.setHidden(ServiceTestUtil.randomBoolean());

    newDLFolder.setOverrideFileEntryTypes(ServiceTestUtil.randomBoolean());

    newDLFolder.setStatus(ServiceTestUtil.nextInt());

    newDLFolder.setStatusByUserId(ServiceTestUtil.nextLong());

    newDLFolder.setStatusByUserName(ServiceTestUtil.randomString());

    newDLFolder.setStatusDate(ServiceTestUtil.nextDate());

    _persistence.update(newDLFolder);

    DLFolder existingDLFolder = _persistence.findByPrimaryKey(newDLFolder.getPrimaryKey());

    Assert.assertEquals(existingDLFolder.getUuid(), newDLFolder.getUuid());
    Assert.assertEquals(existingDLFolder.getFolderId(), newDLFolder.getFolderId());
    Assert.assertEquals(existingDLFolder.getGroupId(), newDLFolder.getGroupId());
    Assert.assertEquals(existingDLFolder.getCompanyId(), newDLFolder.getCompanyId());
    Assert.assertEquals(existingDLFolder.getUserId(), newDLFolder.getUserId());
    Assert.assertEquals(existingDLFolder.getUserName(), newDLFolder.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFolder.getCreateDate()),
        Time.getShortTimestamp(newDLFolder.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFolder.getModifiedDate()),
        Time.getShortTimestamp(newDLFolder.getModifiedDate()));
    Assert.assertEquals(existingDLFolder.getRepositoryId(), newDLFolder.getRepositoryId());
    Assert.assertEquals(existingDLFolder.getMountPoint(), newDLFolder.getMountPoint());
    Assert.assertEquals(existingDLFolder.getParentFolderId(), newDLFolder.getParentFolderId());
    Assert.assertEquals(existingDLFolder.getName(), newDLFolder.getName());
    Assert.assertEquals(existingDLFolder.getDescription(), newDLFolder.getDescription());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFolder.getLastPostDate()),
        Time.getShortTimestamp(newDLFolder.getLastPostDate()));
    Assert.assertEquals(
        existingDLFolder.getDefaultFileEntryTypeId(), newDLFolder.getDefaultFileEntryTypeId());
    Assert.assertEquals(existingDLFolder.getHidden(), newDLFolder.getHidden());
    Assert.assertEquals(
        existingDLFolder.getOverrideFileEntryTypes(), newDLFolder.getOverrideFileEntryTypes());
    Assert.assertEquals(existingDLFolder.getStatus(), newDLFolder.getStatus());
    Assert.assertEquals(existingDLFolder.getStatusByUserId(), newDLFolder.getStatusByUserId());
    Assert.assertEquals(existingDLFolder.getStatusByUserName(), newDLFolder.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDLFolder.getStatusDate()),
        Time.getShortTimestamp(newDLFolder.getStatusDate()));
  }
  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;
  }