Skip to content

Method: getDiskNumber()

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:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.Immutable;
31: import java.util.Collections;
32: import java.util.List;
33: import java.util.Optional;
34: import java.net.URL;
35: import org.eclipse.rdf4j.query.BindingSet;
36: import org.eclipse.rdf4j.repository.Repository;
37: import it.tidalwave.bluemarine2.model.audio.Record;
38: import it.tidalwave.bluemarine2.model.finder.audio.TrackFinder;
39: import it.tidalwave.bluemarine2.model.impl.catalog.finder.RepositoryOptimizedTrackFinder;
40: import it.tidalwave.bluemarine2.model.impl.catalog.finder.RepositoryRecordImageFinder;
41: import lombok.Getter;
42: import lombok.extern.slf4j.Slf4j;
43:
44: /***********************************************************************************************************************
45: *
46: * An implementation of {@link Record} that is mapped to a {@link Repository}.
47: *
48: * @stereotype Datum
49: *
50: * @author Fabrizio Giudici
51: *
52: **********************************************************************************************************************/
53: @Immutable @Getter @Slf4j
54: public class RepositoryRecord extends RepositoryEntitySupport implements Record
55: {
56: @Getter @Nonnull
57: private final Optional<Integer> diskNumber;
58:
59: @Getter @Nonnull
60: private final Optional<Integer> diskCount;
61:
62: @Getter @Nonnull
63: private final Optional<Integer> trackCount; // FIXME: should be used as a shortcut for queries
64:
65: @Getter @Nonnull
66: private final Optional<String> asin;
67:
68: @Getter @Nonnull
69: private final Optional<String> gtin;
70:
71: public RepositoryRecord (@Nonnull final Repository repository, @Nonnull final BindingSet bindingSet)
72: {
73: super(repository, bindingSet, "record");
74: diskNumber = toInteger(bindingSet.getBinding("disk_number"));
75: diskCount = toInteger(bindingSet.getBinding("disk_count"));
76: trackCount = toInteger(bindingSet.getBinding("track_count"));
77: asin = toString(bindingSet.getBinding("asin"));
78: gtin = toString(bindingSet.getBinding("gtin"));
79: }
80:
81: @Override @Nonnull
82: public TrackFinder findTracks()
83: {
84: return configured(new RepositoryOptimizedTrackFinder(repository, trackCount)).inRecord(this);
85: }
86:
87: @Override @Nonnull
88: public Optional<URL> getImageUrl()
89: {
90: final List<? extends URL> imageUrls = new RepositoryRecordImageFinder(repository, this).results();
91: // FIXME: check - images are ordered by size
92: Collections.reverse(imageUrls);
93: return imageUrls.isEmpty() ? Optional.empty() : Optional.of(imageUrls.get(0));
94: }
95:
96: @Override @Nonnull
97: public String toString()
98: {
99: return String.format("RepositoryRecord(rdfs:label=%s, %s)", rdfsLabel, id);
100: }
101: }