1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.message.broker.api.series;
23
24 import org.opencastproject.message.broker.api.MessageItem;
25 import org.opencastproject.metadata.dublincore.DublinCore;
26 import org.opencastproject.metadata.dublincore.DublinCoreCatalog;
27 import org.opencastproject.metadata.dublincore.DublinCoreXmlFormat;
28 import org.opencastproject.security.api.AccessControlList;
29 import org.opencastproject.security.api.AccessControlParser;
30
31 import java.io.IOException;
32 import java.io.Serializable;
33
34
35
36
37 public final class SeriesItem implements MessageItem, Serializable {
38
39 private static final long serialVersionUID = 3275142857854793612L;
40
41 private final Type type;
42 private final String seriesId;
43 private final String series;
44 private final String acl;
45 private final String propertyName;
46 private final String propertyValue;
47 private final String element;
48 private final String elementType;
49 private final String overrideEpisodeAcl;
50
51 public enum Type {
52 UpdateCatalog, UpdateElement, UpdateAcl, Delete
53 };
54
55
56
57
58
59
60 public static SeriesItem updateCatalog(DublinCoreCatalog series) {
61 return new SeriesItem(Type.UpdateCatalog, null, series, null, null, null, null, null, null);
62 }
63
64
65
66
67
68
69
70
71
72
73 public static SeriesItem updateElement(String seriesId, String type, String data) {
74 return new SeriesItem(Type.UpdateElement, seriesId, null, null, null, null, type, data, null);
75 }
76
77
78
79
80
81
82
83
84
85
86 public static SeriesItem updateAcl(String seriesId, AccessControlList acl, boolean overrideEpisodeAcl) {
87 return new SeriesItem(Type.UpdateAcl, seriesId, null, AccessControlParser.toJsonSilent(acl), null, null, null,
88 null, overrideEpisodeAcl);
89 }
90
91
92
93
94
95
96 public static SeriesItem delete(String seriesId) {
97 return new SeriesItem(Type.Delete, seriesId, null, null, null, null, null, null, null);
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 private SeriesItem(Type type, String seriesId, DublinCoreCatalog series, String acl, String propertyName,
127 String propertyValue, String elementType, String element, Boolean overrideEpisodeAcl) {
128 if (seriesId != null && series != null && !seriesId.equals(series.getFirst(DublinCore.PROPERTY_IDENTIFIER))) {
129 throw new IllegalStateException("Provided series ID and dublincore series ID does not match");
130 }
131
132 this.type = type;
133 if (series != null) {
134 try {
135 this.series = series.toXmlString();
136 } catch (IOException e) {
137 throw new IllegalStateException(e);
138 }
139 } else {
140 this.series = null;
141 }
142 if (seriesId != null) {
143 this.seriesId = seriesId;
144 } else if (series != null) {
145 this.seriesId = series.getFirst(DublinCore.PROPERTY_IDENTIFIER);
146 } else {
147 throw new IllegalStateException("Neither series nor series ID is provided");
148 }
149 this.acl = acl;
150 this.propertyName = propertyName;
151 this.propertyValue = propertyValue;
152 this.elementType = elementType;
153 this.element = element;
154 this.overrideEpisodeAcl = overrideEpisodeAcl == null ? null : overrideEpisodeAcl.toString();
155 }
156
157 @Override
158 public String getId() {
159 return seriesId;
160 }
161
162 public Type getType() {
163 return type;
164 }
165
166 public String getSeriesId() {
167 return seriesId;
168 }
169
170 public DublinCoreCatalog getMetadata() {
171 return DublinCoreXmlFormat.readOpt(series).orNull();
172 }
173
174 public DublinCoreCatalog getExtendedMetadata() {
175 try {
176 return DublinCoreXmlFormat.read(element);
177 } catch (Exception ex) {
178 return null;
179 }
180 }
181
182 public AccessControlList getAcl() {
183 try {
184 return acl == null ? null : AccessControlParser.parseAcl(acl);
185 } catch (Exception e) {
186 throw new IllegalStateException();
187 }
188 }
189
190 public String getPropertyName() {
191 return propertyName;
192 }
193
194 public String getPropertyValue() {
195 return propertyValue;
196 }
197
198
199 public String getElement() {
200 return element;
201 }
202
203 public String getElementType() {
204 return elementType;
205 }
206
207 public Boolean getOverrideEpisodeAcl() {
208 return overrideEpisodeAcl == null ? null : Boolean.parseBoolean(overrideEpisodeAcl);
209 }
210 }