Skip to content

Package: RepositoryTrack

RepositoryTrack

nameinstructionbranchcomplexitylinemethod
RepositoryTrack(Repository, BindingSet)
M: 0 C: 77
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
getAudioFile()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDiskCount()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDiskNumber()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDuration()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMetadata()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPerformance()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRecord()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getTrackNumber()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getPerformance$2()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getRecord$1()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$new$0(Repository, BindingSet)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toDumpString()
M: 0 C: 61
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
toString()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

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.time.Duration;
32: import java.util.Optional;
33: import java.nio.file.Path;
34: import org.eclipse.rdf4j.query.BindingSet;
35: import org.eclipse.rdf4j.repository.Repository;
36: import it.tidalwave.util.Id;
37: import it.tidalwave.util.Memoize;
38: import it.tidalwave.bluemarine2.util.Formatters;
39: import it.tidalwave.bluemarine2.model.MediaItem.Metadata;
40: import it.tidalwave.bluemarine2.model.audio.AudioFile;
41: import it.tidalwave.bluemarine2.model.audio.Performance;
42: import it.tidalwave.bluemarine2.model.audio.Record;
43: import it.tidalwave.bluemarine2.model.audio.Track;
44: import it.tidalwave.bluemarine2.model.role.AudioFileSupplier;
45: import it.tidalwave.bluemarine2.model.spi.MetadataSupport;
46: import lombok.Getter;
47: import lombok.extern.slf4j.Slf4j;
48: import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;
49:
50: /***********************************************************************************************************************
51: *
52: * An implementation of {@link Track} that is mapped to a {@link Repository}.
53: *
54: * @stereotype Datum
55: *
56: * @author Fabrizio Giudici
57: *
58: **********************************************************************************************************************/
59: @Immutable @Slf4j
60: public class RepositoryTrack extends RepositoryEntitySupport implements Track, AudioFileSupplier
61: {
62: @Getter @Nonnull
63: private final Optional<Integer> diskNumber; // really property of Record, but handy here
64:
65: @Getter @Nonnull
66: private final Optional<Integer> diskCount; // really property of Record, but handy here
67:
68: @Getter @Nonnull
69: private final Optional<Integer> trackNumber;
70:
71: @Getter @Nonnull
72: private final Optional<Duration> duration;
73:
74: @Getter @Nonnull
75: private final Metadata metadata;
76:
77: @Nonnull
78: private final Path audioFilePath;
79:
80: @Nonnull
81: private final Memoize<AudioFile> audioFile;
82:
83: private final Memoize<Optional<Record>> record = new Memoize<>();
84:
85: private final Memoize<Optional<Performance>> performance = new Memoize<>();
86:
87: public RepositoryTrack (@Nonnull final Repository repository, @Nonnull final BindingSet bindingSet)
88: {
89: super(repository, bindingSet, "track");
90:
91: audioFilePath = toPath(bindingSet.getBinding("path"));
92: duration = toDuration(bindingSet.getBinding("duration"));
93: trackNumber = toInteger(bindingSet.getBinding("track_number"));
94: diskNumber = toInteger(bindingSet.getBinding("disk_number"));
95: diskCount = toInteger(bindingSet.getBinding("disk_count"));
96: // this.recordRdfsLabel = toString(bindingSet.getBinding("record_label"));
97:
98: metadata = new MetadataSupport(audioFilePath).with(DURATION, duration)
99: .with(TRACK_NUMBER, trackNumber)
100: .with(DISK_NUMBER, diskNumber)
101: .with(DISK_COUNT, diskCount);
102:
103: audioFile = new Memoize<>(() -> new RepositoryAudioFile(repository, bindingSet));
104: }
105:
106: @Override @Nonnull
107: public Optional<Record> getRecord()
108: {
109: return record.get(() -> _findRecords().containingTrack(this).optionalFirstResult());
110: }
111:
112: @Override @Nonnull
113: public Optional<Performance> getPerformance()
114: {
115: return performance.get(() -> _findPerformances().ofTrack(this).optionalFirstResult());
116: }
117:
118: @Override @Nonnull
119: public AudioFile getAudioFile()
120: {
121: return audioFile.get();
122: }
123:
124: @Override @Nonnull
125: public String toString()
126: {
127: return String.format("RepositoryTrack(%02d/%02d %02d, %s, rdfs:label=%s, %s, %s)",
128: diskNumber.orElse(1), diskCount.orElse(1), trackNumber.orElse(1),
129: duration.map(Formatters::format).orElse("??:??"), rdfsLabel, audioFilePath, id);
130: }
131:
132: @Override @Nonnull
133: public String toDumpString()
134: {
135: return String.format("%02d/%02d %02d %s %s (%s) %s - %s",
136: diskNumber.orElse(1), diskCount.orElse(1), trackNumber.orElse(1),
137: duration.map(Formatters::format).orElse("??:??"), rdfsLabel, id, audioFilePath,
138: source.orElse(Id.of("unknown")));
139: }
140: }