RepositoryMusicPerformer.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;

  28. import javax.annotation.Nonnull;
  29. import java.util.Collection;
  30. import java.util.Optional;
  31. import it.tidalwave.util.Id;
  32. import it.tidalwave.bluemarine2.model.audio.MusicArtist;
  33. import it.tidalwave.bluemarine2.model.audio.MusicPerformer;
  34. import it.tidalwave.bluemarine2.model.vocabulary.BMMO;
  35. import it.tidalwave.bluemarine2.model.spi.Entity;
  36. import lombok.EqualsAndHashCode;
  37. import lombok.Getter;
  38. import lombok.ToString;
  39. import org.eclipse.rdf4j.query.BindingSet;
  40. import org.eclipse.rdf4j.repository.Repository;

  41. /***********************************************************************************************************************
  42.  *
  43.  * @author  Fabrizio Giudici
  44.  *
  45.  **********************************************************************************************************************/
  46. @Getter @EqualsAndHashCode @ToString
  47. public class RepositoryMusicPerformer implements MusicPerformer
  48.   {
  49.     @Nonnull
  50.     private final MusicArtist musicArtist;

  51.     @Nonnull
  52.     private final Optional<Entity> role;

  53. //    @Delegate
  54. //    private final PriorityAsSupport asSupport = new PriorityAsSupport(this);

  55.     public RepositoryMusicPerformer (@Nonnull final Repository repository, @Nonnull final BindingSet bindingSet)
  56.       {
  57.         this.musicArtist = new RepositoryMusicArtist(repository, bindingSet);
  58.         final Optional<String> r = Optional.of(bindingSet.getBinding("role").getValue().stringValue()
  59.                                                 .replaceAll(BMMO.NS + "performer_", ""));
  60.         this.role = r.map(RepositoryMusicPerformerRole::new);
  61.       }

  62.     @Override @Nonnull
  63.     public Id getId()
  64.       {
  65.         return musicArtist.getId();
  66.       }

  67.     // FIXME: should delegate first to its own AsDelegate and only as a fallaback to MusicArtist
  68.     @Override @Nonnull
  69.     public <T> T as(@Nonnull Class<T> type)
  70.       {
  71.         return musicArtist.as(type);
  72.       }

  73.     @Override @Nonnull
  74.     public <T> T as(@Nonnull Class<T> type, @Nonnull NotFoundBehaviour<T> notFoundBehaviour)
  75.       {
  76.         return musicArtist.as(type, notFoundBehaviour);
  77.       }

  78.     @Override @Nonnull
  79.     public <T> Collection<T> asMany(@Nonnull Class<T> type)
  80.       {
  81.         return musicArtist.asMany(type);
  82.       }
  83.   }