View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
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   * Provides access to the parsed editing information
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 Boolean local;
66  
67    private final String metadataJSON;
68  
69    public EditingData(List<SegmentData> segments, List<TrackData> tracks, List<WorkflowData> workflows, Long duration,
70            String title, String recordingStartDate, String seriesId, String seriesName, Boolean workflowActive,
71            List<String> waveformURIs, List<Subtitle> subtitles, Boolean local, Boolean lockingActive,
72            Integer lockRefresh, User user, String metadataJSON) {
73      this.segments = segments;
74      this.tracks = tracks;
75      this.workflows = workflows;
76      this.duration = duration;
77      this.title = title;
78      this.date = recordingStartDate;
79      this.series = new SeriesData(seriesId, seriesName);
80      this.workflowActive = workflowActive;
81      this.waveformURIs = waveformURIs;
82      this.subtitles = subtitles;
83      this.local = local;
84      this.lockingActive = lockingActive;
85      this.lockRefresh = lockRefresh * 1000;
86      this.lockUUID = UUID.randomUUID().toString();
87      this.lockUser = user.getUsername();
88      this.metadataJSON = metadataJSON;
89    }
90  
91    public static EditingData parse(String json) {
92      requireNonNull(json);
93      Gson gson = new Gson();
94      EditingData editingData = gson.fromJson(json, EditingData.class);
95      requireNonNull(editingData.getTracks());
96      requireNonNull(editingData.getSegments());
97  
98      return editingData;
99    }
100 
101   /**
102    * Returns a list of {@link Tuple} that each represents a segment. {@link Tuple#getA()} marks the start point,
103    * {@link Tuple#getB()} the endpoint of the segement.
104    */
105   public List<SegmentData> getSegments() {
106     return Collections.unmodifiableList(segments);
107   }
108 
109    /**
110    * Returns the optional workflow to start
111    */
112   public String getPostProcessingWorkflow() {
113     return (workflows != null && workflows.size() > 0) ? workflows.get(0).getId() : null;
114   }
115 
116   public List<TrackData> getTracks() {
117     return Collections.unmodifiableList(tracks);
118   }
119 
120   public List<Subtitle> getSubtitles() {
121     return subtitles;
122   }
123 
124   public String getMetadataJSON() {
125     return metadataJSON;
126   }
127 
128   public String toString() {
129     Gson gson = new GsonBuilder().serializeNulls().create();
130     return gson.toJson(this);
131   }
132 
133   public static final class Subtitle {
134     private final String id;
135     /** content of the subtitle */
136     private final String subtitle;
137     private final String[] tags;
138     private final boolean deleted;
139 
140     public Subtitle(String id, String subtitle, String[] tags) {
141       this(id, subtitle, tags,false);
142     }
143 
144     public Subtitle(String id, String subtitle, String[] tags, boolean deleted) {
145       this.id = id;
146       this.subtitle = subtitle;
147       this.tags = tags;
148       this.deleted = deleted;
149     }
150 
151     public String getId() {
152       return id;
153     }
154 
155     public String getSubtitle() {
156       return subtitle;
157     }
158 
159     public String[] getTags() {
160       return tags;
161     }
162 
163     public boolean isDeleted() {
164       return deleted;
165     }
166 
167   }
168 }
169