Class DynamicCollection

java.lang.Object
io.goobi.viewer.model.cms.collections.DynamicCollection
All Implemented Interfaces:
CMSMediaHolder, IPolyglott, BrowseElementInfo, Serializable, Comparable<DynamicCollection>

@Entity public class DynamicCollection extends Object implements Comparable<DynamicCollection>, BrowseElementInfo, CMSMediaHolder, IPolyglott, Serializable
A digital collection defined entirely in the database. Unlike CMSCollection, whose membership is derived from a single Solr field value, a dynamic collection is identified by a unique identifier and its contents are given by an arbitrary solrQuery. It carries a representative image, a label and description in multiple languages and an optional URL linking to a collection page.
See Also:
  • Constructor Details

    • DynamicCollection

      public DynamicCollection()
      Creates a new empty DynamicCollection instance.
    • DynamicCollection

      public DynamicCollection(String identifier)
      Creates a new DynamicCollection with the given identifier.
      Parameters:
      identifier - the unique identifier of the collection
      Throws:
      IllegalArgumentException - if the identifier is null, empty or blank
    • DynamicCollection

      public DynamicCollection(DynamicCollection orig)
      Cloning constructor.
      Parameters:
      orig - the DynamicCollection to clone
  • Method Details

    • loadRepresentativeImage

      public DynamicCollection loadRepresentativeImage()
      Loads representative image access info from Solr.
      Returns:
      this
    • loadRepresentativeImage

      public DynamicCollection loadRepresentativeImage(org.apache.solr.common.SolrDocument recordDoc)
      Sets the thumbnail access permission from an already-fetched representative record document.

      Overload for callers that have loaded the representative record's Solr document in a single batched query, avoiding a per-collection getFirstDoc round-trip. The document is reused for the page lookup as well.

      Parameters:
      recordDoc - top-level Solr document of the representative work, or null to skip
      Returns:
      this
    • getId

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

      public String getName()
      getName.

      The BrowseElementInfo "name" is the collection's immutable identifier.

      Specified by:
      getName in interface BrowseElementInfo
      Returns:
      the name of this browse element
    • getIdentifier

      public String getIdentifier()
      Getter for the field identifier.
      Returns:
      the unique, immutable identifier of the collection
    • setIdentifier

      public void setIdentifier(String identifier)
      Setter for the field identifier.
      Parameters:
      identifier - the unique, immutable identifier of the collection
    • getSolrQuery

      public String getSolrQuery()
      Getter for the field solrQuery.
      Returns:
      the Solr query defining the contents of this collection
    • setSolrQuery

      public void setSolrQuery(String solrQuery)
      Setter for the field solrQuery.
      Parameters:
      solrQuery - the Solr query defining the contents of this collection
    • getSortOrder

      public int getSortOrder()
      Getter for the field sortOrder.
      Returns:
      the ordering position within the flat list of dynamic collections
    • setSortOrder

      public void setSortOrder(int sortOrder)
      Setter for the field sortOrder.
      Parameters:
      sortOrder - the ordering position within the flat list of dynamic collections
    • getMediaItem

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

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

      public String getCollectionUrl()
      Getter for the field collectionUrl.
      Returns:
      the custom URL overriding the default collection browse URL, or null if not set
    • setCollectionUrl

      public void setCollectionUrl(String collectionUrl)
      Setter for the field collectionUrl.
      Parameters:
      collectionUrl - custom URL overriding the default collection browse URL
    • addLabel

      public void addLabel(DynamicCollectionTranslation label)
      Adds a translation for the collection label.
      Parameters:
      label - translation to add as a collection label
    • addDescription

      public void addDescription(DynamicCollectionTranslation description)
      Adds a translation for the collection description.
      Parameters:
      description - translation to add as a collection description
    • pruneEmptyTranslations

      public void pruneEmptyTranslations()
      Removes all label and description translations whose value is blank, so that empty translation rows are not persisted (they are re-created in memory for editing via populateLabels() / populateDescriptions()).
    • getLabels

      public List<DynamicCollectionTranslation> getLabels()
      returns all translations of this collection with the tag LABEL_TAG.
      Returns:
      all labels for this collection
    • getDescriptions

      public List<DynamicCollectionTranslation> getDescriptions()
      returns all translations of this collection with the tag DESCRIPTION_TAG.
      Returns:
      all descriptions for this collection
    • getLabel

      public String getLabel(Locale locale)
      Get the label for the given locale, falling back to the collection identifier if no matching label exists.
      Parameters:
      locale - a Locale object.
      Returns:
      the label string for the given locale, or the collection identifier
    • getLabelAsTranslation

      public DynamicCollectionTranslation getLabelAsTranslation(String language)
      getLabelAsTranslation.
      Parameters:
      language - ISO language code to filter label translations by
      Returns:
      the label translation for the given language, or null if none exists
    • getDescriptionAsTranslation

      public DynamicCollectionTranslation getDescriptionAsTranslation(String language)
      getDescriptionAsTranslation.
      Parameters:
      language - ISO language code to filter description translations by
      Returns:
      the description translation for the given language, or null if none exists
    • getDescriptionAsTranslation

      public DynamicCollectionTranslation getDescriptionAsTranslation()
      Returns:
      DynamicCollectionTranslation
    • getLabelAsTranslation

      public DynamicCollectionTranslation getLabelAsTranslation()
      getLabelAsTranslation for the currently selected locale.
      Returns:
      DynamicCollectionTranslation
    • setLabel

      public void setLabel(String value, String language)
      setLabel.
      Parameters:
      value - new label text to set for the given language
      language - ISO language code identifying the label to update
    • getDescription

      public String getDescription(String language)
      get the description for the given language, or an empty string if no matching description exists.
      Specified by:
      getDescription in interface BrowseElementInfo
      Parameters:
      language - ISO language code identifying the desired description
      Returns:
      the description string for the given language, or an empty string
    • getDescription

      public String getDescription(Locale locale)
      Get the description for the given locale, or an empty string if no matching description exists.
      Parameters:
      locale - a Locale object.
      Returns:
      the description string for the given locale, or an empty string
    • getDescription

      public String getDescription()
      get the description for the current locale, or an empty string if no matching description exists.
      Specified by:
      getDescription in interface BrowseElementInfo
      Returns:
      the description string for the current locale, or an empty string
    • setDescription

      public void setDescription(String value, String language)
      setDescription.
      Parameters:
      value - new description text to set for the given language
      language - ISO language code identifying the description to update
    • populateLabels

      public void populateLabels()
      populateLabels. Ensures a (possibly empty) label translation exists for every supported language.
    • populateLabels

      public void populateLabels(List<String> languages)
      populateLabels.
      Parameters:
      languages - list of language codes to ensure labels exist for
    • populateDescriptions

      public void populateDescriptions()
      populateDescriptions. Ensures a (possibly empty) description translation exists for every supported language.
    • populateDescriptions

      public void populateDescriptions(List<String> languages)
      populateDescriptions.
      Parameters:
      languages - list of language codes to ensure descriptions exist for
    • hasMediaItem

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

      public boolean hasRepresentativeWork()
      hasRepresentativeWork.
      Returns:
      true if this collection has a non-blank representative work persistent identifier, false otherwise
    • hasImage

      public boolean hasImage()
      hasImage.
      Returns:
      true if this collection has a representative work or an associated media item, false otherwise
    • getRepresentativeWorkPI

      public String getRepresentativeWorkPI()
      Getter for the field representativeWorkPI.
      Returns:
      the persistent identifier of the record whose thumbnail represents this collection
    • setRepresentativeWorkPI

      public void setRepresentativeWorkPI(String representativeWorkPI)
      Setter for the field representativeWorkPI.
      Parameters:
      representativeWorkPI - the persistent identifier of the record whose thumbnail represents this collection
    • getRepresentativeWork

      public Optional<StructElement> getRepresentativeWork()
      getRepresentativeWork.
      Returns:
      an Optional containing the representative StructElement, or empty if none is configured or found
    • getFacetString

      public String getFacetString()
      Returns the search facet token identifying this collection, i.e. DC_DYNAMIC:<identifier>. Passed as the facets segment of a search URL, it makes the search list the collection's records with the collection selected as the active facet.
      Returns:
      the unencoded facet token of this collection
    • getLinkURI

      public URI getLinkURI()
      getLinkURI.
      Specified by:
      getLinkURI in interface BrowseElementInfo
      Returns:
      the link URI for this browse element
    • getLinkURI

      public URI getLinkURI(HttpServletRequest request)
      getLinkURI.
      Specified by:
      getLinkURI in interface BrowseElementInfo
      Parameters:
      request - a HttpServletRequest object.
      Returns:
      the link URI for this browse element, resolved relative to the given request context
    • getIconURI

      public URI getIconURI()
      getIconURI.
      Specified by:
      getIconURI in interface BrowseElementInfo
      Returns:
      the icon URI for this browse element, or null if no icon is set
    • getIconURI

      public URI getIconURI(int width, int height)
      getIconURI.
      Specified by:
      getIconURI in interface BrowseElementInfo
      Parameters:
      width - a int.
      height - a int.
      Returns:
      the icon URI scaled to the given width and height, or null if no icon is set
    • getIconURI

      public URI getIconURI(int size)
      getIconURI.
      Specified by:
      getIconURI in interface BrowseElementInfo
      Parameters:
      size - a int.
      Returns:
      the icon URI scaled to the given square size, or null if no icon is set
    • getTranslationsForName

      public de.intranda.metadata.multilanguage.IMetadataValue getTranslationsForName()
      getTranslationsForName.
      Specified by:
      getTranslationsForName in interface BrowseElementInfo
      Returns:
      the multilingual name translations for this browse element
    • getTranslationsForDescription

      public de.intranda.metadata.multilanguage.IMetadataValue getTranslationsForDescription()
      Specified by:
      getTranslationsForDescription in interface BrowseElementInfo
      Returns:
      IMetadataValue
    • 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()
      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
    • getMediaItemWrapper

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

      public boolean isComplete(Locale locale)
      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)
      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 validate required fields for
      Returns:
      true if all required fields contain a value in the given locale
    • isEmpty

      public boolean isEmpty(Locale locale)
      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
    • getSelectedLocale

      public Locale getSelectedLocale()
      Specified by:
      getSelectedLocale in interface IPolyglott
      Returns:
      the locale currently set by IPolyglott.setSelectedLocale(Locale)
    • setSelectedLocale

      public void setSelectedLocale(Locale locale)
      Sets the locale to use for display and editing.
      Specified by:
      setSelectedLocale in interface IPolyglott
      Parameters:
      locale - the locale to select
    • getAccessPermissionThumbnail

      public AccessPermission getAccessPermissionThumbnail()
    • setAccessPermissionThumbnail

      public void setAccessPermissionThumbnail(AccessPermission accessPermissionThumbnail)
    • contentEquals

      public boolean contentEquals(DynamicCollection other)
      Parameters:
      other - the other DynamicCollection to compare content with
      Returns:
      true if the persisted content of this collection matches the given collection, false otherwise
    • compareTo

      public int compareTo(DynamicCollection other)

      Compares collections by the alphabetical sorting of their getName()

      Specified by:
      compareTo in interface Comparable<DynamicCollection>
    • hashCode

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

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

      public String toString()
      Overrides:
      toString in class Object