java.lang.Object
io.goobi.viewer.model.crowdsourcing.campaigns.Campaign
All Implemented Interfaces:
CMSMediaHolder, ILicenseType, IPolyglott, Serializable

@Entity public class Campaign extends Object implements CMSMediaHolder, ILicenseType, IPolyglott, Serializable
A Campaign is a template to create annotations of specific types for a limited set of target resources and optionally by limited user group within a limited time frame. The types of annotations created are determined by the Questions contained in this Campaign
Author:
Florian Alpers
See Also:
  • Constructor Details

    • Campaign

      public Campaign()
      Empty constructor.
    • Campaign

      public Campaign(Locale selectedLocale)
      Locale constructor.
      Parameters:
      selectedLocale - locale used for editing translations
    • Campaign

      public Campaign(Campaign orig)
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getCampaignVisibilityValues

      public List<Campaign.CampaignVisibility> getCampaignVisibilityValues()
      getCampaignVisibilityValues.
      Returns:
      available values of the CampaignVisibility enum
    • getNumRecords

      public long getNumRecords() throws IndexUnreachableException
      getNumRecords.
      Returns:
      total number of records encompassed by the configured solrQuery
      Throws:
      IndexUnreachableException - if any.
    • getNumRecordsForStatus

      public long getNumRecordsForStatus(String status)
      getNumRecordsForStatus.
      Parameters:
      status - crowdsourcing status name to count records for
      Returns:
      number of records with the given status
    • getNumRecordsToAnnotate

      public long getNumRecordsToAnnotate() throws IndexUnreachableException
      getNumRecordsToAnnotate.
      Returns:
      Number of records whose status is neither REVIEW nor FINISHED
      Throws:
      IndexUnreachableException - if any.
    • getContributorCount

      public long getContributorCount() throws DAOException
      Determines the number of distinct users that have created or reviewed annotations in the context of this campaign.
      Returns:
      number of users who either annotated or reviewed annotations
      Throws:
      DAOException - if any.
    • isHasAnnotations

      public boolean isHasAnnotations()
      Returns:
      true if this campaign has at least one annotation; false otherwise
    • getProgress

      public int getProgress() throws IndexUnreachableException, PresentationException
      FINISHED records in percent.
      Returns:
      percentage of records marked as finished relative to the total number or records
      Throws:
      IndexUnreachableException - if any.
      PresentationException - if any.
    • getDaysBeforeStart

      public long getDaysBeforeStart()
      Returns the number of whole days between today and the starting date for this campaign.
      Returns:
      whole days left between today and dateStart; -1 if no dateStart
    • getDaysLeft

      public long getDaysLeft()
      Returns the number of whole days between today and the end date for this campaign. Because this method only returns the number of whole days left, its main purpose is for displaying the number of days to the user, and it shouldn't be used for access control.
      Returns:
      whole days left between today and dateEnd; -1 if no dateEnd
    • getDaysLeftAsString

      public String getDaysLeftAsString()
      getDaysLeftAsString.
      Returns:
      number of days left as string; infinity symbol if no dateEnd
    • isHasStarted

      public boolean isHasStarted()
      isHasStarted.
      Returns:
      true if dateStart lies after now; false otherwise
    • isHasEnded

      public boolean isHasEnded()
      isHasEnded.
      Returns:
      true if dateEnd lies before now; false otherwise
    • isUserAllowedAction

      public boolean isUserAllowedAction(User user, CrowdsourcingStatus status) throws PresentationException, IndexUnreachableException, DAOException
      Checks whether the given user may annotate or review records based on the given status.
      Parameters:
      user - user whose permission is checked; may be null for anonymous
      status - desired action (ANNOTATE or REVIEW) to check permission for
      Returns:
      true if the given user is allowed to perform the action associated with the given status; false otherwise
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
      DAOException - if any.
    • isUserMayEdit

      public boolean isUserMayEdit(User user) throws DAOException
      Parameters:
      user - User for whom to check access
      Returns:
      true if given User has permission to edit this Campaign; false otherwise
      Throws:
      DAOException
    • getName

      public String getName()
      Specified by:
      getName in interface ILicenseType
    • getTitle

      public String getTitle()
      Returns the title value in the current language of the campaign object (current tab). This is meant to be used for campaign editing only, since the language will not be in sync with the selected locale!
      Returns:
      the campaign title in the currently selected editing locale
    • setTitle

      public void setTitle(String title)
      setTitle.
      Parameters:
      title - title text in the currently selected locale
    • getMenuTitle

      public String getMenuTitle()
      Returns the menu title value in the current language of the campaign object (current tab). This is meant to be used for campaign editing only, since the language will not be in sync with the selected locale!
      Returns:
      the campaign menu title in the currently selected editing locale
    • getMenuTitleOrElseTitle

      public String getMenuTitleOrElseTitle()
      getMenuTitleOrElseTitle.
      Returns:
      the campaign menu title in the currently selected locale, falling back to the title if no menu title is set
    • getMenuTitleOrElseTitle

      public String getMenuTitleOrElseTitle(String lang, boolean useFallback)
      getMenuTitleOrElseTitle.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      useFallback - whether to fall back to the default language translation
      Returns:
      the menu title in the given language, falling back to the title if not available
    • setMenuTitle

      public void setMenuTitle(String menuTitle)
      setMenuTitle.
      Parameters:
      menuTitle - menu title text in the currently selected locale
    • getDescription

      public String getDescription()
      Returns the description value in the current language of the campaign object (current tab). This is meant to be used for campaign editing only, since the language will not be in sync with the selected locale!
      Returns:
      Description value in the current language in the campaign object
    • setDescription

      public void setDescription(String description)
      setDescription.
      Parameters:
      description - description text in the currently selected locale
    • getTitle

      public String getTitle(String lang)
      getTitle.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      Returns:
      the campaign title in the given language, without fallback
    • getTitle

      public String getTitle(String lang, boolean useFallback)
      getTitle.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      useFallback - whether to fall back to the default language translation
      Returns:
      the title of the given language or if it doesn't exist the title of the default language
    • getDescription

      public String getDescription(String lang)
      getDescription.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      Returns:
      the campaign description in the given language, without fallback
    • getDescription

      public String getDescription(String lang, boolean useFallback)
      getDescription.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      useFallback - whether to fall back to the default language translation
      Returns:
      the campaign description in the given language, optionally falling back to the default language
    • getMenuTitle

      public String getMenuTitle(String lang)
      getMenuTitle.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      Returns:
      the campaign menu title in the given language, without fallback
    • getMenuTitle

      public String getMenuTitle(String lang, boolean useFallback)
      getMenuTitle.
      Parameters:
      lang - BCP 47 language tag for the requested translation
      useFallback - whether to fall back to the default language translation
      Returns:
      the campaign menu title in the given language, optionally falling back to the default language
    • getDisplayTitle

      public String getDisplayTitle()
    • getDisplayDescription

      public String getDisplayDescription()
    • getId

      public Long getId()
      Getter for the field id.
      Returns:
      the database primary key of this campaign
    • getId

      public static Long getId(URI idAsURI)
      Getter for the field id.
      Parameters:
      idAsURI - campaign REST API URI containing the numeric ID
      Returns:
      the numeric campaign ID extracted from the URI, or null if not found
    • getIdAsURI

      public URI getIdAsURI()
      getIdAsURI.
      Returns:
      the REST API URI for this campaign, constructed from the campaign ID
    • setId

      public void setId(Long id)
      Setter for the field id.
      Parameters:
      id - the database primary key to set
    • getDateCreated

      public LocalDateTime getDateCreated()
      Getter for the field dateCreated.
      Returns:
      the date and time when this campaign was created
    • setDateCreated

      public void setDateCreated(LocalDateTime dateCreated)
      Setter for the field dateCreated.
      Parameters:
      dateCreated - the date and time when this campaign was created
    • getDateUpdated

      public LocalDateTime getDateUpdated()
      Getter for the field dateUpdated.
      Returns:
      the date and time when this campaign was last updated
    • setDateUpdated

      public void setDateUpdated(LocalDateTime dateUpdated)
      Setter for the field dateUpdated.
      Parameters:
      dateUpdated - the date and time when this campaign was last updated
    • getVisibility

      public Campaign.CampaignVisibility getVisibility()
      Getter for the field visibility.
      Returns:
      the visibility setting controlling who can see and participate in this campaign
    • setVisibility

      public void setVisibility(Campaign.CampaignVisibility visibility)
      Setter for the field visibility.
      Parameters:
      visibility - the visibility setting controlling who can see and participate in this campaign
    • getDateOnlyStart

      public LocalDate getDateOnlyStart()
      Returns:
      LocalDate
    • setDateOnlyStart

      public void setDateOnlyStart(LocalDate dateStart)
      Parameters:
      dateStart - the campaign start date (date only, no time)
    • getDateStart

      public LocalDateTime getDateStart()
      Getter for the field dateStart.
      Returns:
      the date and time when this campaign becomes active
    • setDateStart

      public void setDateStart(LocalDateTime dateStart)
      Setter for the field dateStart.
      Parameters:
      dateStart - the date and time when this campaign becomes active
    • getDateOnlyEnd

      public LocalDate getDateOnlyEnd()
      Returns:
      LocalDate
    • setDateOnlyEnd

      public void setDateOnlyEnd(LocalDate dateEnd)
      Parameters:
      dateEnd - the campaign end date (date only, no time)
    • getDateEnd

      public LocalDateTime getDateEnd()
      Getter for the field dateEnd.
      Returns:
      the date and time when this campaign ends
    • setDateEnd

      public void setDateEnd(LocalDateTime dateEnd)
      Setter for the field dateEnd.
      Parameters:
      dateEnd - the date and time when this campaign ends
    • getSolrQuery

      public String getSolrQuery()
      Getter for the field solrQuery.
      Returns:
      the Solr query defining the set of records covered by this campaign
    • setSolrQuery

      public void setSolrQuery(String solrQuery)
      Setter for the field solrQuery.
      Parameters:
      solrQuery - the Solr query defining the set of records covered by this campaign
    • getPermalink

      public String getPermalink()
      Getter for the field permalink.
      Returns:
      the permanent URL path for this campaign's public page
    • setPermalink

      public void setPermalink(String permalink)
      Setter for the field permalink.
      Parameters:
      permalink - the permanent URL path for this campaign's public page
    • getBreadcrumbParentCmsPageId

      public String getBreadcrumbParentCmsPageId()
      Getter for the field breadcrumbParentCmsPageId.
      Returns:
      the ID of the CMS page to use as parent in the breadcrumb navigation
    • setBreadcrumbParentCmsPageId

      public void setBreadcrumbParentCmsPageId(String breadcrumbParentCmsPageId)
      Setter for the field breadcrumbParentCmsPageId.
      Parameters:
      breadcrumbParentCmsPageId - the ID of the CMS page to use as parent in the breadcrumb navigation
    • getTranslations

      public List<CampaignTranslation> getTranslations()
      Getter for the field translations.
      Returns:
      the list of translations for this campaign's localizable text fields
    • setTranslations

      public void setTranslations(List<CampaignTranslation> translations)
      Setter for the field translations.
      Parameters:
      translations - list of campaign translations replacing the current one
    • getQuestions

      public List<Question> getQuestions()
      Getter for the field questions.
      Returns:
      the list of annotation question templates belonging to this campaign
    • setQuestions

      public void setQuestions(List<Question> questions)
      Setter for the field questions.
      Parameters:
      questions - list of annotation question templates to assign
    • getStatistics

      public Map<String,CampaignRecordStatistic> getStatistics()
      Getter for the field statistics.
      Returns:
      the map of record statistics keyed by persistent identifier
    • setStatistics

      public void setStatistics(Map<String,CampaignRecordStatistic> statistics)
      Setter for the field statistics.
      Parameters:
      statistics - map of record statistics keyed by persistent identifier
    • getSelectedLocale

      public Locale getSelectedLocale()
      Getter for the field selectedLocale.
      Specified by:
      getSelectedLocale in interface IPolyglott
      Returns:
      the locale used to select the active translation tab in the UI
    • setSelectedLocale

      public void setSelectedLocale(Locale selectedLocale)
      Setter for the field selectedLocale.
      Specified by:
      setSelectedLocale in interface IPolyglott
      Parameters:
      selectedLocale - locale used to select the active translation tab
    • isReady

      public boolean isReady()
      Return true if the campaign is ready for use. For this, the title in the default language must exists and there must be at least one question
      Returns:
      true if the campaign is fully configured and ready to accept contributions, false otherwise
    • isComplete

      public boolean isComplete(Locale locale)
      Description copied from interface: IPolyglott
      If this returns true, an associated language tab should have the 'already-translated' class, otherwise the '-partly-translated' class unless IPolyglott.isEmpty(Locale) also returns true.
      Specified by:
      isComplete in interface IPolyglott
      Parameters:
      locale - the locale to check translation completeness for
      Returns:
      true if IPolyglott.isValid(Locale) returns true for the given locale and all fields contain a value which have a value in the default locale. For the default locale, IPolyglott.isComplete(Locale) and IPolyglott.isValid(Locale) are identical. For implementations with only one field, both methods are also always identical
    • isValid

      public boolean isValid(Locale locale)
      Description copied from interface: IPolyglott
      Only meaningful for the default language for which all required fields must be filled.
      Specified by:
      isValid in interface IPolyglott
      Parameters:
      locale - the locale to check validity for
      Returns:
      true if the title is not empty for the given locale
    • isEmpty

      public boolean isEmpty(Locale locale)
      Description copied from interface: IPolyglott
      If this returns true, an associated language tab should have neither the 'already-translated' nor the '-partly-translated' class.
      Specified by:
      isEmpty in interface IPolyglott
      Parameters:
      locale - the locale to check for empty fields
      Returns:
      true if no fields are filled for the given locale
    • getRandomizedTarget

      public String getRandomizedTarget(CrowdsourcingStatus status, String piToIgnore, User user) throws PresentationException, IndexUnreachableException
      Get the targetIdentifier to a random PI from the Solr query result list.
      Parameters:
      status - desired record status to filter candidates by
      piToIgnore - persistent identifier of the record to exclude
      user - the user requesting the target; used to filter eligible records
      Returns:
      the persistent identifier of a randomly selected eligible target record, or an empty string if none is available
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getNextTarget

      public String getNextTarget(CrowdsourcingStatus status, String currentPi, User user) throws PresentationException, IndexUnreachableException
      Get the targetIdentifier to a random PI from the Solr query result list.
      Parameters:
      status - desired record status to filter candidates by
      currentPi - persistent identifier of the currently viewed record
      user - the user requesting the target; used to filter eligible records
      Returns:
      the persistent identifier of the next eligible target record after the current one, or an empty string if none is available
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • resetSolrQueryResults

      public void resetSolrQueryResults()
    • isEligibleToEdit

      public boolean isEligibleToEdit(String pi, CrowdsourcingStatus status, User user)
      Checks if the given user may annotate/review (depending on status) a specific pi within this campaign.
      Parameters:
      pi - persistent identifier of the record to check
      status - desired action (ANNOTATE or REVIEW) to check eligibility for
      user - user whose eligibility is checked; may be null for anonymous
      Returns:
      true if
      • the status is REVIEW and the user is not contained in the annotators list
      • or
      • the status is ANNOTATE and the user is not contained in the reviewers list
      • or
      • The user is admin
      • or
      • The user is null
    • hasRecordsToReview

      public boolean hasRecordsToReview(User user) throws PresentationException, IndexUnreachableException
      Check if the given user is eligible to review any records.
      Parameters:
      user - user for whom eligible review records are checked
      Returns:
      true if there are any records in review status for which isEligibleToEdit(String, CrowdsourcingStatus, User) returns true
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • hasRecordsToAnnotate

      public boolean hasRecordsToAnnotate(User user) throws PresentationException, IndexUnreachableException
      Check if the given user is eligible to annotate any records.
      Parameters:
      user - user for whom eligible annotation records are checked
      Returns:
      true if there are any records in annotate status for which isEligibleToEdit(String, CrowdsourcingStatus, User) returns true
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • mayAnnotate

      public boolean mayAnnotate(User user, String pi) throws PresentationException, IndexUnreachableException
      Check if the user is allowed to annotate the given pi for this campaign.
      Parameters:
      user - user requesting annotation access; may be null for anonymous
      pi - persistent identifier of the record to annotate
      Returns:
      true if the pi is ready for annotation and the user hasn't reviewed it or is a superuser
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • mayReview

      public boolean mayReview(User user, String pi) throws PresentationException, IndexUnreachableException
      Check if the user is allowed to review the given pi for this campaign.
      Parameters:
      user - user requesting review access; may be null for anonymous
      pi - persistent identifier of the record to review
      Returns:
      true if the pi is ready for review and the user hasn't annotated it or is a superuser
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getRecordStatus

      public CrowdsourcingStatus getRecordStatus(String pi)
      getRecordStatus.
      Parameters:
      pi - persistent identifier of the record to look up
      Returns:
      record status for the given pi
    • getPageStatus

      public CrowdsourcingStatus getPageStatus(String pi, int page)
    • isGroupLimitActive

      public boolean isGroupLimitActive()
      Returns:
      true if this Campaign is limited to a UserGroup; false otherwise
    • isReviewGroupLimitActive

      public boolean isReviewGroupLimitActive()
    • isReviewModeActive

      public boolean isReviewModeActive()
    • setRecordStatus

      public void setRecordStatus(String pi, CrowdsourcingStatus status, Optional<User> user)
      Updates record status in the campaign statistics.
      Parameters:
      pi - persistent identifier of the record being updated
      status - new crowdsourcing status to assign to the record
      user - optional user performing the annotation or review
    • setRecordPageStatus

      public void setRecordPageStatus(String pi, int page, CrowdsourcingStatus status, Optional<User> user)
      Parameters:
      pi - the persistent identifier of the record
      page - the physical page number
      status - the new crowdsourcing status to set
      user - the user performing the status update
    • setMediaItem

      public void setMediaItem(CMSMediaItem item)
      setMediaItem.
      Specified by:
      setMediaItem in interface CMSMediaHolder
      Parameters:
      item - a CMSMediaItem object.
    • getMediaItem

      public CMSMediaItem getMediaItem()
      getMediaItem.
      Specified by:
      getMediaItem in interface CMSMediaHolder
      Returns:
      the associated CMS media item, or null if none is set
    • getMediaFilter

      public String getMediaFilter()
      A regular expression determining which filenames are shown in the media list and may be uploaded.
      Specified by:
      getMediaFilter in interface CMSMediaHolder
      Returns:
      the regex pattern used to filter acceptable media filenames for this holder
    • getMediaTypes

      public String getMediaTypes()
      Description copied from interface: CMSMediaHolder
      A string representing the allowed media formates for a user. Should be a comma separated list of format names or filename suffixes
      Specified by:
      getMediaTypes in interface CMSMediaHolder
      Returns:
      String
    • hasMediaItem

      public boolean hasMediaItem()
      hasMediaItem.
      Specified by:
      hasMediaItem in interface CMSMediaHolder
      Returns:
      true if this holder has an associated CMS media item, false otherwise
    • setShowLog

      public void setShowLog(boolean showLog)
    • isShowLog

      public boolean isShowLog()
    • isLimitToGroup

      public boolean isLimitToGroup()
    • setLimitToGroup

      public void setLimitToGroup(boolean limitToGroup)
    • getReviewMode

      public Campaign.ReviewMode getReviewMode()
    • setReviewMode

      public void setReviewMode(Campaign.ReviewMode reviewMode)
    • getStatisticMode

      public Campaign.StatisticMode getStatisticMode()
    • setStatisticMode

      public void setStatisticMode(Campaign.StatisticMode statisticMode)
    • getUserGroup

      public UserGroup getUserGroup()
    • setUserGroup

      public void setUserGroup(UserGroup userGroup)
    • getReviewerUserGroup

      public UserGroup getReviewerUserGroup()
    • setReviewerUserGroup

      public void setReviewerUserGroup(UserGroup reviewerUserGroup)
    • isTimePeriodEnabled

      public boolean isTimePeriodEnabled()
    • isRestrictAnnotationAccess

      public boolean isRestrictAnnotationAccess()
      Returns:
      the restrictAnnotationAccess
    • setRestrictAnnotationAccess

      public void setRestrictAnnotationAccess(boolean restrictAnnotationAccess)
      Parameters:
      restrictAnnotationAccess - the restrictAnnotationAccess to set
    • setTimePeriodEnabled

      public void setTimePeriodEnabled(boolean timePeriodEnabled)
    • getLogMessages

      public List<CampaignLogMessage> getLogMessages()
    • addLogMessage

      public CampaignLogMessage addLogMessage(LogMessage message, String pi)
    • deleteLogMessage

      public void deleteLogMessage(Long messageId)
      Parameters:
      messageId - the ID of the log message to delete
    • getMediaItemWrapper

      public CategorizableTranslatedSelectable<CMSMediaItem> getMediaItemWrapper()
      getMediaItemWrapper.
      Specified by:
      getMediaItemWrapper in interface CMSMediaHolder
      Returns:
      the CMS media item wrapped with category and selection state information
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAccessConditionValue

      public String getAccessConditionValue()
      Returns:
      String