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