@Override
  public Folder addAttachmentsFolder() throws PortalException {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }

    ServiceContext serviceContext = new ServiceContext();

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

    Repository repository =
        PortletFileRepositoryUtil.addPortletRepository(
            getGroupId(), PortletKeys.BACKGROUND_TASK, serviceContext);

    Folder folder =
        PortletFileRepositoryUtil.addPortletFolder(
            getUserId(),
            repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            String.valueOf(getBackgroundTaskId()),
            serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
  }
  @Override
  public long getAttachmentsFolderId() {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return _attachmentsFolderId;
    }

    ServiceContext serviceContext = new ServiceContext();

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

    Repository repository =
        PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(), PortletKeys.BACKGROUND_TASK);

    if (repository == null) {
      return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

    try {
      Folder folder =
          PortletFileRepositoryUtil.getPortletFolder(
              repository.getRepositoryId(),
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              String.valueOf(getBackgroundTaskId()));

      _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("No portlet repository for background task " + getBackgroundTaskId(), e);
      }
    }

    return _attachmentsFolderId;
  }