java.lang.Object
io.goobi.viewer.model.iiif.presentation.v2.builder.AbstractBuilder
Direct Known Subclasses:
CollectionBuilder, LayerBuilder, ManifestBuilder, SequenceBuilder, StructureBuilder

public abstract class AbstractBuilder extends Object
Abstract base class for IIIF Presentation API v2 resource builders, providing shared URI construction and metadata helpers.
Author:
Florian Alpers
  • Field Details

    • REQUIRED_SOLR_FIELDS

      protected static final String[] REQUIRED_SOLR_FIELDS
      Constant REQUIRED_SOLR_FIELDS.
    • urls

      protected final AbstractApiUrlManager urls
      Constant UGC_SOLR_FIELDS.
    • config

      protected final Configuration config
  • Constructor Details

    • AbstractBuilder

      protected AbstractBuilder(AbstractApiUrlManager apiUrlManager)
      Creates a new AbstractBuilder instance.
      Parameters:
      apiUrlManager - API URL manager for building IIIF resource URIs
    • AbstractBuilder

      protected AbstractBuilder(AbstractApiUrlManager apiUrlManager, Configuration config)
      Creates a new AbstractBuilder instance.
      Parameters:
      apiUrlManager - API URL manager for building IIIF resource URIs
      config - viewer configuration instance
  • Method Details

    • getLabel

      protected de.intranda.metadata.multilanguage.IMetadataValue getLabel(String value)
      Parameters:
      value - message key or literal string to translate
      Returns:
      IMetadataValue
    • absolutize

      public URI absolutize(URI uri)
      Parameters:
      uri - the URI to make absolute; returned unchanged if already absolute
      Returns:
      URI
    • absolutize

      public URI absolutize(String uri)
    • getLocale

      protected Locale getLocale(String language)
      getLocale.
      Parameters:
      language - BCP 47 language tag string
      Returns:
      the Locale for the given language tag, defaulting to English if not resolvable
    • getMetsResolverUrl

      public String getMetsResolverUrl(StructElement ele)
      getMetsResolverUrl.
      Parameters:
      ele - structure element whose PI is used to build the URL
      Returns:
      METS resolver link for the DFG Viewer
    • getLidoResolverUrl

      public String getLidoResolverUrl(StructElement ele)
      getLidoResolverUrl.
      Parameters:
      ele - structure element whose PI is used to build the URL
      Returns:
      LIDO resolver link for the DFG Viewer
    • getViewUrl

      public String getViewUrl(PhysicalElement ele, PageType pageType)
      getViewUrl.
      Parameters:
      ele - physical page element whose PURL part is appended to the URL
      pageType - page type determining the viewer URL prefix
      Returns:
      viewer url for the given page in the given PageType
    • getLabelIfExists

      public Optional<de.intranda.metadata.multilanguage.IMetadataValue> getLabelIfExists(org.apache.solr.common.SolrDocument solrDocument)
      Simple method to create a label for a SolrDocument from SolrConstants.LABEL, SolrConstants.TITLE or SolrConstants.DOCSTRCT.
      Parameters:
      solrDocument - Solr document to extract label information from
      Returns:
      an Optional containing the label derived from LABEL, TITLE, or DOCSTRCT fields, or empty if none are present
    • addMetadata

      public void addMetadata(de.intranda.api.iiif.presentation.v2.AbstractPresentationModelElement2 manifest, StructElement ele)
      addMetadata.
      Parameters:
      manifest - IIIF presentation element to attach metadata to
      ele - structure element providing the metadata values
    • addCrowdourcingAnnotations

      public void addCrowdourcingAnnotations(List<de.intranda.api.iiif.presentation.v2.Canvas2> canvases, Map<Integer,List<de.intranda.api.annotation.oa.OpenAnnotation>> crowdsourcingAnnotations, Map<de.intranda.api.iiif.presentation.enums.AnnotationType,List<de.intranda.api.iiif.presentation.v2.AnnotationList>> annotationMap)
      Adds the annotations from the crowdsourcingAnnotations map to the respective canvases in the canvases list as well as to the given annotationMap.
      Parameters:
      canvases - The list of canvases which should receive the annotations as otherContent
      crowdsourcingAnnotations - A map of annotations by page number
      annotationMap - A global annotation map for a whole manifest; may be null if not needed
    • contained

      protected boolean contained(String field, List<String> displayFields)
      Return true if the field is contained in displayFields, accounting for wildcard characters.
      Parameters:
      field - Solr field name to look up
      displayFields - list of configured display field names (may contain wildcards)
      Returns:
      true if displayFields contains field; false otherwise
    • addLanguageFields

      protected static List<String> addLanguageFields(List<String> displayFields, List<Locale> locales)
      Parameters:
      displayFields - list of base Solr field names to expand
      locales - locales for which language-specific field variants should be added
      Returns:
      List (immutable!)
    • getDocumentWithChildren

      public List<StructElement> getDocumentWithChildren(String pi) throws PresentationException, IndexUnreachableException
      Queries all DocStructs which have the given PI as PI_TOPSTRUCT or anchor (or are the anchor themselves). Works are sorted by a StructElementComparator If no hits are found, an empty list is returned.
      Parameters:
      pi - persistent identifier of the top-level record
      Returns:
      A list of all docstructs with the given pi or children thereof. An empty list if no hits are found
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • addEventMetadataToWorkElement

      protected void addEventMetadataToWorkElement(List<StructElement> eles, List<org.apache.solr.common.SolrDocument> events)
      Adds all metadata from the given events to the first work document contained in eles. All metadata will be attached twice, once in the form "/[fieldName]" and once in the form "[eventType]/[fieldName]"
      Parameters:
      eles - The list of StructElements from which to select the first work document. All metadata are attached to this document
      events - The list of event SolrDocuments from which to take the metadata
    • getEventFields

      protected Map<String,List<String>> getEventFields()
      getEventFields.
      Returns:
      a map of event type names to their associated Solr field names, as configured for IIIF
    • getDocument

      getDocument.
      Parameters:
      pi - persistent identifier of the record to load
      Returns:
      the StructElement for the given PI, or null if the document was not found
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getSolrFieldList

      public List<String> getSolrFieldList()
      getSolrFieldList.
      Returns:
      a list of Solr field names required for IIIF presentation data retrieval
    • getAttributions

      protected List<de.intranda.metadata.multilanguage.IMetadataValue> getAttributions()
      Gets the attribution text configured in webapi.iiif.attribution and returns all translations if any are found, or the configured string itself otherwise.
      Returns:
      the configured attribution
    • getDescription

      protected Optional<de.intranda.metadata.multilanguage.IMetadataValue> getDescription(StructElement ele)
      getDescription.
      Parameters:
      ele - structure element to extract description fields from
      Returns:
      an Optional containing the description metadata value, or empty if no configured field has a value
    • getLabel

      protected Optional<de.intranda.metadata.multilanguage.IMetadataValue> getLabel(StructElement ele)
      getDescription.
      Parameters:
      ele - structure element to extract label fields from
      Returns:
      an Optional containing the label metadata value, or empty if no configured field has a value
    • getCollectionURI

      public URI getCollectionURI(String collectionField, String baseCollectionName)
      getCollectionURI.
      Parameters:
      collectionField - Solr field used to group the collection
      baseCollectionName - top-level collection name, or blank for root collection
      Returns:
      the URI identifying the IIIF collection resource
    • getManifestURI

      public URI getManifestURI(String pi)
      getManifestURI.
      Parameters:
      pi - persistent identifier of the record
      Returns:
      the manifest URI for the given record, using an external URL if configured
    • getExternalManifestURI

      public Optional<URI> getExternalManifestURI(String pi)
    • getPageManifestURI

      public URI getPageManifestURI(String pi, int pageNo)
      getManifestURI for page.
      Parameters:
      pi - Persistent identifier of a record
      pageNo - 1-based page order within the record
      Returns:
      the manifest URI for the specified page of the given record
    • getManifestURI

      public URI getManifestURI(String pi, BuildMode mode)
      getManifestURI.
      Parameters:
      pi - persistent identifier of the record
      mode - build mode appended as a query parameter
      Returns:
      the manifest URI for the given record with the build mode as a query parameter
    • getRangeURI

      public URI getRangeURI(String pi, String logId)
      getRangeURI.
      Parameters:
      pi - persistent identifier of the record
      logId - logical structure element ID for the range
      Returns:
      the range URI for the given record and logical structure element
    • getSequenceURI

      public URI getSequenceURI(String pi, String label)
      getSequenceURI.
      Parameters:
      pi - persistent identifier of the record
      label - sequence label; defaults to "basic" if blank
      Returns:
      the sequence URI for the given record and label
    • getCanvasURI

      public URI getCanvasURI(String pi, int pageNo)
      getCanvasURI.
      Parameters:
      pi - persistent identifier of the record
      pageNo - 1-based physical page order number
      Returns:
      the canvas URI for the given page of the record
    • getPageOrderFromCanvasURI

      public Integer getPageOrderFromCanvasURI(URI uri)
      Get the page order (1-based) from a canvas URI. That is the number in the last path parameter after '/canvas/' If the URI doesn't match a canvas URI, null is returned
      Parameters:
      uri - canvas URI to extract the page order from
      Returns:
      the 1-based page order number extracted from the canvas URI, or null if the URI does not match
    • getPIFromCanvasURI

      public String getPIFromCanvasURI(URI uri)
      Get the persistent identifier from a canvas URI. This is the URI path param between '/iiif/manifests/' and '/canvas/'
      Parameters:
      uri - canvas URI to extract the persistent identifier from
      Returns:
      The pi, or null if the URI doesn't match a iiif canvas URI
    • getAnnotationListURI

      public URI getAnnotationListURI(String pi, int pageNo, de.intranda.api.iiif.presentation.enums.AnnotationType type, boolean openAnnotation)
      getAnnotationListURI.
      Parameters:
      pi - persistent identifier of the record
      pageNo - 1-based physical page order number
      type - annotation type determining the URL path
      openAnnotation - if true, appends a format=oa query parameter for Open Annotation format
      Returns:
      the annotation list URI for the given record page and annotation type
    • getAnnotationListURI

      public URI getAnnotationListURI(String pi, de.intranda.api.iiif.presentation.enums.AnnotationType type)
      getAnnotationListURI.
      Parameters:
      pi - persistent identifier of the record
      type - annotation type appended as a query parameter
      Returns:
      the annotation list URI for the given record and annotation type
    • getCommentAnnotationURI

      public URI getCommentAnnotationURI(long id)
      getCommentAnnotationURI.
      Parameters:
      id - database ID of the comment annotation
      Returns:
      the URI identifying the comment annotation with the given ID
    • getLayerURI

      public URI getLayerURI(String pi, de.intranda.api.iiif.presentation.enums.AnnotationType type)
      getLayerURI.
      Parameters:
      pi - persistent identifier of the record
      type - annotation type identifying the layer
      Returns:
      the layer URI for the given record and annotation type
    • getImageAnnotationURI

      public URI getImageAnnotationURI(String pi, int order)
      getImageAnnotationURI.
      Parameters:
      pi - persistent identifier of the record
      order - 1-based physical page order number
      Returns:
      the image annotation URI for the given page of the record
    • getAnnotationURI

      public URI getAnnotationURI(String pi, int order, de.intranda.api.iiif.presentation.enums.AnnotationType type, int annoNum) throws URISyntaxException
      getAnnotationURI.
      Parameters:
      pi - persistent identifier of the record
      order - 1-based physical page order number
      type - annotation type used as a path segment
      annoNum - 1-based annotation index within the page
      Returns:
      the URI identifying the specific annotation on the given page
      Throws:
      URISyntaxException - if any.
    • getAnnotationURI

      public URI getAnnotationURI(String id)
      getAnnotationURI.
      Parameters:
      id - annotation ID used as a path parameter
      Returns:
      the URI identifying the annotation with the given ID
    • getSearchServiceURI

      public URI getSearchServiceURI(String pi)
      Get URL to search service from ApiUrls.
      Parameters:
      pi - The persistent identifier of the work to search
      Returns:
      the service URI
    • getAutoCompleteServiceURI

      public URI getAutoCompleteServiceURI(String pi)
      Get URL to auto complete service from ApiUrls.
      Parameters:
      pi - The persistent identifier of the work to search for autocomplete
      Returns:
      the service URI
    • getSearchURI

      public URI getSearchURI(String pi, String query, List<String> motivation)
      getSearchURI.
      Parameters:
      pi - persistent identifier of the record to search within
      query - search term appended as the q parameter
      motivation - list of motivation strings to filter results
      Returns:
      the search URI for the given record with the query and motivation parameters
    • getAutoSuggestURI

      public URI getAutoSuggestURI(String pi, String query, List<String> motivation)
      getAutoSuggestURI.
      Parameters:
      pi - persistent identifier of the record to autocomplete within
      query - partial search term for autocomplete suggestions
      motivation - list of motivation strings to filter suggestions
      Returns:
      the autocomplete URI for the given record with the query and motivation parameters
    • addSeeAlso

      public AbstractBuilder addSeeAlso(LinkingProperty.LinkingTarget target, de.intranda.metadata.multilanguage.IMetadataValue label)
    • addRendering

      public AbstractBuilder addRendering(LinkingProperty.LinkingTarget target, de.intranda.metadata.multilanguage.IMetadataValue label)
    • getSeeAlsos

      public List<LinkingProperty> getSeeAlsos()
    • getRenderings

      public List<LinkingProperty> getRenderings()