Skip to content

Method: prepareQuery()

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.Track;
34: import it.tidalwave.bluemarine2.model.finder.audio.TrackFinder;
35: import lombok.ToString;
36:
37: /***********************************************************************************************************************
38: *
39: * @author Fabrizio Giudici
40: *
41: **********************************************************************************************************************/
42: @ToString
43: public class RepositoryTrackFinder extends RepositoryFinderSupport<Track, TrackFinder>
44: implements TrackFinder
45: {
46: private static final long serialVersionUID = 770942161753738572L;
47:
48: private static final String QUERY_TRACKS = readSparql(RepositoryTrackFinder.class, "Tracks.sparql");
49:
50: @Nonnull
51: protected final Optional<Id> makerId;
52:
53: @Nonnull
54: protected final Optional<Id> recordId;
55:
56: /*******************************************************************************************************************
57: *
58: * Default constructor.
59: *
60: ******************************************************************************************************************/
61: public RepositoryTrackFinder (@Nonnull final Repository repository)
62: {
63: this(repository, Optional.empty(), Optional.empty());
64: }
65:
66: /*******************************************************************************************************************
67: *
68: * Clone constructor.
69: *
70: ******************************************************************************************************************/
71: public RepositoryTrackFinder (@Nonnull final RepositoryTrackFinder other, @Nonnull final Object override)
72: {
73: super(other, override);
74: final RepositoryTrackFinder source = getSource(RepositoryTrackFinder.class, other, override);
75: this.makerId = source.makerId;
76: this.recordId = source.recordId;
77: }
78:
79: /*******************************************************************************************************************
80: *
81: * Override constructor.
82: *
83: ******************************************************************************************************************/
84: private RepositoryTrackFinder (@Nonnull final Repository repository,
85: @Nonnull final Optional<Id> makerId,
86: @Nonnull final Optional<Id> recordId)
87: {
88: super(repository, "track");
89: this.makerId = makerId;
90: this.recordId = recordId;
91: }
92:
93: /*******************************************************************************************************************
94: *
95: * {@inheritDoc}
96: *
97: ******************************************************************************************************************/
98: @Override @Nonnull
99: public TrackFinder madeBy (@Nonnull final Id artistId)
100: {
101: return clonedWith(new RepositoryTrackFinder(repository, Optional.of(artistId), recordId));
102: }
103:
104: /*******************************************************************************************************************
105: *
106: * {@inheritDoc}
107: *
108: ******************************************************************************************************************/
109: @Override @Nonnull
110: public TrackFinder inRecord (@Nonnull final Id recordId)
111: {
112: return clonedWith(new RepositoryTrackFinder(repository, makerId, Optional.of(recordId)));
113: }
114:
115: /*******************************************************************************************************************
116: *
117: * {@inheritDoc}
118: *
119: ******************************************************************************************************************/
120: @Override @Nonnull
121: protected QueryAndParameters prepareQuery()
122: {
123: return QueryAndParameters.withSparql(QUERY_TRACKS)
124: .withParameter("artist", makerId.map(this::iriFor))
125: .withParameter("record", recordId.map(this::iriFor));
126: }
127: }