RepositoryPerformanceFinder.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * blueMarine II: Semantic Media Centre
  5.  * http://tidalwave.it/projects/bluemarine2
  6.  *
  7.  * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/bluemarine2-src
  23.  * git clone https://github.com/tidalwave-it/bluemarine2-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.bluemarine2.model.impl.catalog.finder;

  28. import javax.annotation.Nonnull;
  29. import java.util.Optional;
  30. import org.eclipse.rdf4j.repository.Repository;
  31. import it.tidalwave.util.Id;
  32. import it.tidalwave.bluemarine2.model.audio.Performance;
  33. import it.tidalwave.bluemarine2.model.finder.audio.PerformanceFinder;
  34. import lombok.ToString;

  35. /***********************************************************************************************************************
  36.  *
  37.  * @stereotype      Finder
  38.  *
  39.  * @author  Fabrizio Giudici
  40.  *
  41.  **********************************************************************************************************************/
  42. @ToString
  43. public class RepositoryPerformanceFinder extends RepositoryFinderSupport<Performance, PerformanceFinder>
  44.                                          implements PerformanceFinder
  45.   {
  46.     private static final long serialVersionUID = -5065032203985453428L;

  47.     private static final String QUERY_PERFORMANCES = readSparql(RepositoryPerformanceFinder.class, "Performances.sparql");

  48.     @Nonnull
  49.     private final Optional<Id> trackId;

  50.     @Nonnull
  51.     private final Optional<Id> performerId;

  52.     /*******************************************************************************************************************
  53.      *
  54.      * Default constructor.
  55.      *
  56.      ******************************************************************************************************************/
  57.     public RepositoryPerformanceFinder (@Nonnull final Repository repository)
  58.       {
  59.         this(repository, Optional.empty(), Optional.empty());
  60.       }

  61.     /*******************************************************************************************************************
  62.      *
  63.      * Clone constructor.
  64.      *
  65.      ******************************************************************************************************************/
  66.     public RepositoryPerformanceFinder (@Nonnull final RepositoryPerformanceFinder other,
  67.                                         @Nonnull final Object override)
  68.       {
  69.         super(other, override);
  70.         final RepositoryPerformanceFinder source = getSource(RepositoryPerformanceFinder.class, other, override);
  71.         this.trackId = source.trackId;
  72.         this.performerId = source.performerId;
  73.       }

  74.     /*******************************************************************************************************************
  75.      *
  76.      * Override constructor.
  77.      *
  78.      ******************************************************************************************************************/
  79.     private RepositoryPerformanceFinder (@Nonnull final Repository repository,
  80.                                          @Nonnull final Optional<Id> trackId,
  81.                                          @Nonnull final Optional<Id> performerId)
  82.       {
  83.         super(repository, "performance");
  84.         this.trackId = trackId;
  85.         this.performerId = performerId;
  86.       }

  87.     /*******************************************************************************************************************
  88.      *
  89.      * {@inheritDoc}
  90.      *
  91.      ******************************************************************************************************************/
  92.     @Override @Nonnull
  93.     public PerformanceFinder ofTrack (@Nonnull final Id trackId)
  94.       {
  95.         return clonedWith(new RepositoryPerformanceFinder(repository, Optional.of(trackId), performerId));
  96.       }

  97.     /*******************************************************************************************************************
  98.      *
  99.      * {@inheritDoc}
  100.      *
  101.      ******************************************************************************************************************/
  102.     @Override @Nonnull
  103.     public PerformanceFinder performedBy (@Nonnull final Id performerId)
  104.       {
  105.         return clonedWith(new RepositoryPerformanceFinder(repository, trackId, Optional.of(performerId)));
  106.       }

  107.     /*******************************************************************************************************************
  108.      *
  109.      * {@inheritDoc}
  110.      *
  111.      ******************************************************************************************************************/
  112.     @Override @Nonnull
  113.     protected QueryAndParameters prepareQuery()
  114.       {
  115.         return QueryAndParameters.withSparql(QUERY_PERFORMANCES)
  116.                                  .withParameter("track",  trackId.map(this::iriFor))
  117.                                  .withParameter("artist", performerId.map(this::iriFor));
  118.       }
  119.   }