1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opencastproject.editor.api;
22
23 import static java.util.Objects.requireNonNull;
24
25 import org.opencastproject.security.api.User;
26 import org.opencastproject.util.data.Tuple;
27
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import com.google.gson.annotations.SerializedName;
31
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.UUID;
35
36
37
38
39 public class EditingData {
40 public static final String WORKFLOW_ACTIVE = "workflow_active";
41 public static final String LOCKING_ACTIVE = "locking_active";
42 public static final String LOCK_REFRESH = "lock_refresh";
43 public static final String LOCK_UUID = "lock_uuid";
44 public static final String LOCK_USER = "lock_user";
45 private final List<SegmentData> segments;
46 private final List<WorkflowData> workflows;
47 private final List<TrackData> tracks;
48 private final String title;
49 private final String date;
50 private final Long duration;
51 private final SeriesData series;
52 @SerializedName(WORKFLOW_ACTIVE)
53 private final Boolean workflowActive;
54 @SerializedName(LOCKING_ACTIVE)
55 private final Boolean lockingActive;
56 @SerializedName(LOCK_REFRESH)
57 private final Integer lockRefresh;
58 @SerializedName(LOCK_UUID)
59 private final String lockUUID;
60 @SerializedName(LOCK_USER)
61 private final String lockUser;
62
63 private final List<String> waveformURIs;
64 private final List<Subtitle> subtitles;
65 private final List<Subtitle> chapters;
66 private final Boolean local;
67
68 private final String metadataJSON;
69
70 public EditingData(List<SegmentData> segments, List<TrackData> tracks, List<WorkflowData> workflows, Long duration,
71 String title, String recordingStartDate, String seriesId, String seriesName, Boolean workflowActive,
72 List<String> waveformURIs, List<Subtitle> subtitles, List<Subtitle> chapters, Boolean local,
73 Boolean lockingActive, Integer lockRefresh, User user, String metadataJSON) {
74 this.segments = segments;
75 this.tracks = tracks;
76 this.workflows = workflows;
77 this.duration = duration;
78 this.title = title;
79 this.date = recordingStartDate;
80 this.series = new SeriesData(seriesId, seriesName);
81 this.workflowActive = workflowActive;
82 this.waveformURIs = waveformURIs;
83 this.subtitles = subtitles;
84 this.chapters = chapters;
85 this.local = local;
86 this.lockingActive = lockingActive;
87 this.lockRefresh = lockRefresh * 1000;
88 this.lockUUID = UUID.randomUUID().toString();
89 this.lockUser = user.getUsername();
90 this.metadataJSON = metadataJSON;
91 }
92
93 public static EditingData parse(String json) {
94 requireNonNull(json);
95 Gson gson = new Gson();
96 EditingData editingData = gson.fromJson(json, EditingData.class);
97 requireNonNull(editingData.getTracks());
98 requireNonNull(editingData.getSegments());
99
100 return editingData;
101 }
102
103
104
105
106
107 public List<SegmentData> getSegments() {
108 return Collections.unmodifiableList(segments);
109 }
110
111
112
113
114 public String getPostProcessingWorkflow() {
115 return (workflows != null && workflows.size() > 0) ? workflows.get(0).getId() : null;
116 }
117
118 public List<TrackData> getTracks() {
119 return Collections.unmodifiableList(tracks);
120 }
121
122 public List<Subtitle> getSubtitles() {
123 return subtitles;
124 }
125
126 public List<Subtitle> getChapters() {
127 return chapters;
128 }
129
130 public String getMetadataJSON() {
131 return metadataJSON;
132 }
133
134 public String toString() {
135 Gson gson = new GsonBuilder().serializeNulls().create();
136 return gson.toJson(this);
137 }
138
139 public static final class Subtitle {
140 private final String id;
141
142 private final String subtitle;
143 private final String[] tags;
144 private final boolean deleted;
145
146 public Subtitle(String id, String subtitle, String[] tags) {
147 this(id, subtitle, tags,false);
148 }
149
150 public Subtitle(String id, String subtitle, String[] tags, boolean deleted) {
151 this.id = id;
152 this.subtitle = subtitle;
153 this.tags = tags;
154 this.deleted = deleted;
155 }
156
157 public String getId() {
158 return id;
159 }
160
161 public String getSubtitle() {
162 return subtitle;
163 }
164
165 public String[] getTags() {
166 return tags;
167 }
168
169 public boolean isDeleted() {
170 return deleted;
171 }
172
173 }
174 }
175