1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opencastproject.assetmanager.impl.query;
22
23 import static com.entwinemedia.fn.Equality.eq;
24 import static com.entwinemedia.fn.Equality.hash;
25
26 import org.opencastproject.assetmanager.api.Property;
27 import org.opencastproject.assetmanager.api.Snapshot;
28 import org.opencastproject.assetmanager.api.query.ARecord;
29 import org.opencastproject.assetmanager.impl.persistence.SnapshotDto;
30
31 import com.entwinemedia.fn.Fn;
32 import com.entwinemedia.fn.data.Opt;
33
34 import java.util.List;
35 import java.util.Optional;
36
37 public final class ARecordImpl implements ARecord {
38 private final long snapshotId;
39 private final String mediaPackageId;
40 private final List<Property> properties;
41 private Optional<Snapshot> snapshot;
42 private Opt<SnapshotDto> snapshotDto;
43
44 public ARecordImpl(
45 long snapshotId,
46 String mediaPackageId,
47 List<Property> properties) {
48 this.snapshotId = snapshotId;
49 this.mediaPackageId = mediaPackageId;
50 this.properties = properties;
51 this.snapshot = Optional.empty();
52 this.snapshotDto = Opt.none(SnapshotDto.class);
53 }
54
55 public ARecordImpl(
56 long snapshotId,
57 String mediaPackageId,
58 List<Property> properties,
59 Snapshot snapshot) {
60 this(snapshotId, mediaPackageId, properties);
61 if (snapshot != null) {
62 this.snapshot = Optional.of(snapshot);
63 }
64 }
65
66 public ARecordImpl(
67 long snapshotId,
68 String mediaPackageId,
69 List<Property> properties,
70 SnapshotDto snapshotDto) {
71 this(snapshotId, mediaPackageId, properties);
72 if (snapshotDto != null) {
73 this.snapshotDto = Opt.some(snapshotDto);
74 }
75 }
76
77
78
79 public long getSnapshotId() {
80 return snapshotId;
81 }
82
83 @Override public String getMediaPackageId() {
84 return mediaPackageId;
85 }
86
87 @Override public List<Property> getProperties() {
88 return properties;
89 }
90
91
92
93
94
95
96
97
98 @Override public Optional<Snapshot> getSnapshot() {
99 if (snapshot.isEmpty() && snapshotDto.isSome()) {
100 snapshot = Optional.of(snapshotDto.get().toSnapshot());
101 }
102 return snapshot;
103 }
104
105
106 public Opt<SnapshotDto> getSnapshotDto() {
107 return snapshotDto;
108 }
109
110 @Override public int hashCode() {
111 return hash(snapshotId);
112 }
113
114
115 @Override public boolean equals(Object that) {
116 return (this == that) || (that instanceof ARecordImpl && eqFields((ARecordImpl) that));
117 }
118
119 private boolean eqFields(ARecordImpl that) {
120 return eq(snapshotId, that.snapshotId);
121 }
122
123 public static final Fn<ARecordImpl, String> getMediaPackageId = new Fn<ARecordImpl, String>() {
124 @Override public String apply(ARecordImpl a) {
125 return a.getMediaPackageId();
126 }
127 };
128 }