Skip to contentMethod: toString()
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:
29: import javax.annotation.Nonnull;
30: import java.util.Optional;
31: import org.eclipse.rdf4j.repository.Repository;
32: import it.tidalwave.util.Id;
33: import it.tidalwave.bluemarine2.model.audio.MusicArtist;
34: import it.tidalwave.bluemarine2.model.finder.audio.MusicArtistFinder;
35: import lombok.ToString;
36:
37: /***********************************************************************************************************************
38: *
39: * @author Fabrizio Giudici
40: *
41: **********************************************************************************************************************/
42: @ToString
43: public class RepositoryMusicArtistFinder extends RepositoryFinderSupport<MusicArtist, MusicArtistFinder>
44: implements MusicArtistFinder
45: {
46: private static final long serialVersionUID = 2271161001432418095L;
47:
48: private static final String QUERY_ARTISTS = readSparql(RepositoryMusicArtistFinder.class, "AllMusicArtists.sparql");
49:
50: private static final String QUERY_ARTISTS_MAKER_OF = readSparql(RepositoryMusicArtistFinder.class, "MakerArtists.sparql");
51:
52: @Nonnull
53: private final Optional<Id> madeEntityId;
54:
55: /*******************************************************************************************************************
56: *
57: * Default constructor.
58: *
59: ******************************************************************************************************************/
60: public RepositoryMusicArtistFinder (@Nonnull final Repository repository)
61: {
62: this(repository, Optional.empty());
63: }
64:
65: /*******************************************************************************************************************
66: *
67: * Clone constructor.
68: *
69: ******************************************************************************************************************/
70: public RepositoryMusicArtistFinder (@Nonnull final RepositoryMusicArtistFinder other,
71: @Nonnull final Object override)
72: {
73: super(other, override);
74: final RepositoryMusicArtistFinder source = getSource(RepositoryMusicArtistFinder.class, other, override);
75: this.madeEntityId = source.madeEntityId;
76: }
77:
78: /*******************************************************************************************************************
79: *
80: * Override constructor.
81: *
82: ******************************************************************************************************************/
83: private RepositoryMusicArtistFinder (@Nonnull final Repository repository,
84: @Nonnull final Optional<Id> madeEntityId)
85: {
86: super(repository, "artist");
87: this.madeEntityId = madeEntityId;
88: }
89:
90: /*******************************************************************************************************************
91: *
92: * {@inheritDoc}
93: *
94: ******************************************************************************************************************/
95: @Override @Nonnull
96: public MusicArtistFinder makerOf (@Nonnull final Id madeEntityId)
97: {
98: return clonedWith(new RepositoryMusicArtistFinder(repository, Optional.of(madeEntityId)));
99: }
100:
101: /*******************************************************************************************************************
102: *
103: * {@inheritDoc}
104: *
105: ******************************************************************************************************************/
106: @Override @Nonnull
107: protected QueryAndParameters prepareQuery()
108: {
109: // Two different queries because for the 'makerOf' we want to include collborations, as it's important their label
110: // In other words, 'Ella Fitzgerald and Duke Ellington' matters, rather than a list of the two individuals
111: return QueryAndParameters.withSparql(madeEntityId.isPresent() ? QUERY_ARTISTS_MAKER_OF : QUERY_ARTISTS)
112: .withParameter("madeEntity", madeEntityId.map(this::iriFor));
113: }
114: }