Class CrowdsourcingBean

java.lang.Object
io.goobi.viewer.managedbeans.CrowdsourcingBean
All Implemented Interfaces:
Serializable

@Named @SessionScoped public class CrowdsourcingBean extends Object implements Serializable
JSF backing bean for crowdsourcing campaign management, providing access to campaigns and annotation tasks.
See Also:
  • Field Details

  • Constructor Details

    • CrowdsourcingBean

      public CrowdsourcingBean()
      Creates a new CrowdsourcingBean instance.
    • CrowdsourcingBean

      public CrowdsourcingBean(Configuration viewerConfig, IDAO dao)
      Creates a new CrowdsourcingBean instance.
      Parameters:
      viewerConfig - viewer configuration used within this bean
      dao - DAO instance for database access
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes all campaigns as lazily loaded list.
    • getCampaignCount

      public long getCampaignCount(Campaign.CampaignVisibility visibility) throws DAOException
      getCampaignCount.
      Parameters:
      visibility - visibility level to filter by, or null for all campaigns
      Returns:
      The total number of campaigns of a certain Campaign.CampaignVisibility
      Throws:
      DAOException - if any.
    • filterCampaignsAction

      public String filterCampaignsAction(Campaign.CampaignVisibility visibility)
      Filter the loaded campaigns by Campaign.CampaignVisibility.
      Parameters:
      visibility - visibility level to filter by, or null to clear the filter
      Returns:
      an empty string after applying the visibility filter to the campaign list
    • getAllLocales

      public static Collection<Locale> getAllLocales()
      getAllLocales.
      Returns:
      A list of all locales supported by this viewer application
    • createNewCampaignAction

      public String createNewCampaignAction()
      Sets a new Campaign as the selectedCampaign and returns a pretty url to the view for creating a new campaign.
      Returns:
      an empty string after initializing a new empty campaign for creation
    • editCampaignAction

      public String editCampaignAction(Campaign campaign)
      Sets the given Campaign as the selectedCampaign and returns a pretty url to the view for editing this campaign.
      Parameters:
      campaign - campaign to open for editing
      Returns:
      the pretty URL name for the campaign edit view
    • deleteCampaignAction

      public String deleteCampaignAction(Campaign campaign) throws DAOException
      Deletes the given Campaign from the database and the loaded list of campaigns.
      Parameters:
      campaign - campaign to delete from the database
      Returns:
      an empty string after deleting the campaign from the database
      Throws:
      DAOException - if any.
    • addNewQuestionAction

      public String addNewQuestionAction()
      Adds a new Question to the selected campaign.
      Returns:
      an empty string after adding the new question to the selected campaign
    • removeQuestionAction

      public String removeQuestionAction(Question question)
      Removes the given Question from the selected campaign.
      Parameters:
      question - question to remove from the selected campaign
      Returns:
      an empty string after removing the question from the selected campaign
    • resetDurationAction

      public String resetDurationAction()
      Resets dateStart + dateEnd to null.
      Returns:
      an empty string after clearing the campaign start and end dates
    • getAllCampaigns

      public List<Campaign> getAllCampaigns() throws DAOException
      getAllCampaigns.
      Returns:
      All campaigns from the database
      Throws:
      DAOException - if any.
    • getAllCampaigns

      public List<Campaign> getAllCampaigns(Campaign.CampaignVisibility visibility) throws DAOException
      getAllCampaigns.
      Parameters:
      visibility - visibility level used to filter the full campaign list
      Returns:
      All campaigns of the given Campaign.CampaignVisibility from the database
      Throws:
      DAOException - if any.
    • getAllowedCampaigns

      public List<Campaign> getAllowedCampaigns(User user) throws DAOException
      Returns the list of campaigns that are visible to the given user.
      Parameters:
      user - user to check campaign visibility for, or null for anonymous access
      Returns:
      List of campaigns allowed to the given user
      Throws:
      DAOException
    • isUserOwnsAnyCampaigns

      public boolean isUserOwnsAnyCampaigns(User user) throws DAOException
      isUserOwnsAnyCampaigns.
      Parameters:
      user - user whose campaign ownership is checked
      Returns:
      true if user owns any existing campaigns; false otherwise
      Throws:
      DAOException
    • isAllowed

      public static boolean isAllowed(User user, Campaign campaign) throws DAOException
      Check if the given user is allowed access to the given campaign from a rights management standpoint alone. If the user is null, access is granted for public campaigns only, otherwise access is granted if the user has the appropriate rights
      Parameters:
      user - user requesting access, or null for anonymous access
      campaign - campaign to evaluate access for
      Returns:
      true if campaign is allowed to the given user; false otherwise
      Throws:
      DAOException - if any.
    • saveSelectedCampaignAction

      public String saveSelectedCampaignAction() throws DAOException, PresentationException, IndexUnreachableException
      Adds the current page to the database, if it doesn't exist or updates it otherwise.
      Returns:
      Navigation outcome
      Throws:
      DAOException - if any.
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getCampaignsRootUrl

      public String getCampaignsRootUrl()
      getCampaignsRootUrl.
      Returns:
      root URL for the permalink value
    • getLazyModelCampaigns

      public TableDataProvider<Campaign> getLazyModelCampaigns()
      Getter for the field lazyModelCampaigns.
      Returns:
      the lazy-loading table data provider for crowdsourcing campaigns
    • getSelectedCampaign

      public Campaign getSelectedCampaign()
      Getter for the field selectedCampaign.
      Returns:
      the currently selected crowdsourcing campaign, or null if none is selected
    • setSelectedCampaign

      public void setSelectedCampaign(Campaign campaign)
      Sets the selected campaign to a clone of the given campaign.
      Parameters:
      campaign - the campaign to select; a deep copy is stored internally
    • getSelectedCampaignId

      public String getSelectedCampaignId()
      getSelectedCampaignId.
      Returns:
      The id of the selectedCampaign as String
    • setSelectedCampaignId

      public void setSelectedCampaignId(String id) throws DAOException
      Sets the selectedCampaign by a String containing the campaign id.
      Parameters:
      id - numeric campaign ID as string, or null to clear selection
      Throws:
      DAOException - if any.
    • isEditMode

      public boolean isEditMode()
      isEditMode.
      Returns:
      true if a campaign with a persisted ID is currently selected (edit mode), false otherwise
    • getTargetCampaign

      public Campaign getTargetCampaign()
      Getter for the field targetCampaign.
      Returns:
      the targetCampaign
    • setTargetCampaign

      public void setTargetCampaign(Campaign targetCampaign)
      Setter for the field targetCampaign.
      Parameters:
      targetCampaign - the campaign to use as the annotation or review target
    • getTargetCampaignId

      public String getTargetCampaignId()
      getTargetCampaignId.
      Returns:
      the identifier of the targetCampaign
    • setTargetCampaignId

      public void setTargetCampaignId(String id) throws NumberFormatException, DAOException
      setTargetCampaignId.
      Parameters:
      id - numeric campaign ID as string, or null to clear the target
      Throws:
      NumberFormatException - if any.
      DAOException - if any.
    • setNextIdentifierForAnnotation

      public void setNextIdentifierForAnnotation() throws PresentationException, IndexUnreachableException
      setNextIdentifierForAnnotation.
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • setNextIdentifierForReview

      public void setNextIdentifierForReview() throws PresentationException, IndexUnreachableException
      setNextIdentifierForReview.
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • resetTarget

      public void resetTarget()
      Removes the target identifier (pi) from the bean, so that pi can be targeted again by random target resolution.
    • forwardToAnnotationTarget

      public String forwardToAnnotationTarget()
      forwardToAnnotationTarget.
      Returns:
      the pretty url to annotatate the targetIdentifier by the targetCampaign
    • forwardToReviewTarget

      public String forwardToReviewTarget()
      forwardToReviewTarget.
      Returns:
      the pretty url to review the targetIdentifier for the targetCampaign
    • getTargetIdentifier

      public String getTargetIdentifier()
      Getter for the field targetIdentifier.
      Returns:
      the PI of a work selected for editing
    • getTargetIdentifierForUrl

      public String getTargetIdentifierForUrl()
      getTargetIdentifierForUrl.
      Returns:
      the PI of a work selected for editing or "-" if no targetIdentifier exists
    • setTargetIdentifierForUrl

      public void setTargetIdentifierForUrl(String pi)
      setTargetIdentifierForUrl.
      Parameters:
      pi - persistent identifier from the URL, or "-" to clear the target
    • setTargetIdentifier

      public void setTargetIdentifier(String targetIdentifier)
      Setter for the field targetIdentifier.
      Parameters:
      targetIdentifier - the persistent identifier (PI) of the record selected for annotation or review
    • getTargetPage

      public int getTargetPage()
      Getter for the field targetPage.
      Returns:
      the page number within the target record to annotate or review
    • setTargetPage

      public void setTargetPage(int targetPage)
      Setter for the field targetPage.
      Parameters:
      targetPage - the page number within the target record to annotate or review
    • forwardToCrowdsourcingAnnotation

      public String forwardToCrowdsourcingAnnotation(Campaign campaign)
      forwardToCrowdsourcingAnnotation.
      Parameters:
      campaign - campaign to set as the annotation target
      Returns:
      a pretty url to annotate a random work with the given Campaign
    • forwardToCrowdsourcingReview

      public String forwardToCrowdsourcingReview(Campaign campaign)
      forwardToCrowdsourcingReview.
      Parameters:
      campaign - campaign to set as the review target
      Returns:
      a pretty url to review a random work with the given Campaign
    • forwardToCrowdsourcingAnnotation

      public String forwardToCrowdsourcingAnnotation(Campaign campaign, String pi)
      forwardToCrowdsourcingAnnotation.
      Parameters:
      campaign - campaign to use for annotating the record
      pi - persistent identifier of the record to annotate
      Returns:
      a pretty url to annotate the work with the given pi with the given Campaign
    • forwardToCrowdsourcingReview

      public String forwardToCrowdsourcingReview(Campaign campaign, String pi)
      forwardToCrowdsourcingReview.
      Parameters:
      campaign - campaign to use for reviewing the record
      pi - persistent identifier of the record to review
      Returns:
      a pretty url to review the work with the given pi with the given Campaign
    • getNextItemUrl

      public String getNextItemUrl(Campaign campaign, CrowdsourcingStatus status)
      getRandomItemUrl.
      Parameters:
      campaign - The campaign with which to annotate/review
      status - if CrowdsourcingStatus.REVIEW, return a url for reviewing, otherwise for annotating
      Returns:
      The pretty url to either review or annotate a random work with the given Campaign
    • getTargetRecordStatus

      public CrowdsourcingStatus getTargetRecordStatus()
      getTargetRecordStatus.
      Returns:
      the CrowdsourcingStatus of the targetCampaign for the targetIdentifier
    • handleInvalidTarget

      public String handleInvalidTarget()
      handleInvalidTarget.
      Returns:
      the pretty URL to the crowdsourcing campaigns page if UserBean.getUser() is not eligible for viewing the targetCampaign
    • getActiveCampaignsForRecord

      public List<Campaign> getActiveCampaignsForRecord(String pi) throws DAOException, PresentationException, IndexUnreachableException
      Returns a list of active campaigns for the given identifier that are visible to the current user.
      Parameters:
      pi - persistent identifier of the record to look up
      Returns:
      List of campaigns
      Throws:
      DAOException - if any.
      PresentationException - if any.
      IndexUnreachableException - if any.
    • updateActiveCampaigns

      public void updateActiveCampaigns() throws DAOException, PresentationException, IndexUnreachableException
      Searches for all identifiers that are encompassed by the Solr query of each active campaign and initializes and fills a map of active campaigns for each identifier. Should be called once after the application first starts (or upon first access) or when a campaign has been updated.
      Throws:
      DAOException - if any.
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getPossibleReviewModes

      public Set<Campaign.ReviewMode> getPossibleReviewModes()
      getPossibleReviewModes.
      Returns:
      the set of all available review mode values
    • getAvailableStatisticModes

      public Set<Campaign.StatisticMode> getAvailableStatisticModes()
      getAvailableStatisticModes.
      Returns:
      List of enum values
    • getTargetStatus

      public CrowdsourcingStatus getTargetStatus()
      Getter for the field targetStatus.
      Returns:
      the crowdsourcing status used to filter or assign to the target
    • setTargetStatus

      public void setTargetStatus(CrowdsourcingStatus targetStatus)
      Setter for the field targetStatus.
      Parameters:
      targetStatus - the crowdsourcing status to filter or assign to the target
    • setTargetStatus

      public void setTargetStatus(String targetStatus)
      Setter for the field targetStatus.
      Parameters:
      targetStatus - status name resolved via CrowdsourcingStatus.forName