Skip to content

Commit 26bedbf

Browse files
committed
Use mixed_text for series subject
1 parent 40d66d8 commit 26bedbf

File tree

7 files changed

+52
-32
lines changed

7 files changed

+52
-32
lines changed

modules/admin-ui/src/main/java/org/opencastproject/adminui/endpoint/SeriesEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private DublinCoreMetadataCollection getSeriesMetadata(Series series) {
422422
MetadataField subject = metadata.getOutputFields().get(DublinCore.PROPERTY_SUBJECT.getLocalName());
423423
metadata.removeField(subject);
424424
MetadataField newSubject = new MetadataField(subject);
425-
newSubject.setValue(series.getSubject());
425+
newSubject.setValue(series.getSubjects());
426426
metadata.addField(newSubject);
427427

428428
MetadataField description = metadata.getOutputFields().get(DublinCore.PROPERTY_DESCRIPTION.getLocalName());

modules/elasticsearch-index/src/main/java/org/opencastproject/elasticsearch/index/objects/series/Series.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.HashMap;
4747
import java.util.List;
4848
import java.util.Map;
49+
import java.util.Objects;
4950

5051
import javax.xml.bind.JAXBContext;
5152
import javax.xml.bind.JAXBException;
@@ -66,8 +67,9 @@
6667
* Object wrapper for a series.
6768
*/
6869
@XmlType(name = "series", namespace = IndexObject.INDEX_XML_NAMESPACE, propOrder = { "identifier", "title",
69-
"description", "subject", "organization", "language", "creator", "license", "extendedMetadata", "accessPolicy",
70-
"managedAcl", "createdDateTime", "organizers", "contributors", "publishers", "rightsHolder", "theme" })
70+
"description", "subjects", "subject", "organization", "language", "creator", "license", "extendedMetadata",
71+
"accessPolicy", "managedAcl", "createdDateTime", "organizers", "contributors", "publishers", "rightsHolder",
72+
"theme" })
7173
@XmlRootElement(name = "series", namespace = IndexObject.INDEX_XML_NAMESPACE)
7274
@XmlAccessorType(XmlAccessType.NONE)
7375
public class Series implements IndexObject {
@@ -91,8 +93,8 @@ public class Series implements IndexObject {
9193
private String description = null;
9294

9395
/** The subject */
94-
@XmlElement(name = "subject")
95-
private String subject = null;
96+
@XmlElement(name = "subjects")
97+
private List<String> subjects = new ArrayList<>();
9698

9799
/** The organization for the series */
98100
@XmlElement(name = "organization")
@@ -251,20 +253,43 @@ public String getDescription() {
251253
/**
252254
* Sets the series subject.
253255
*
254-
* @param subject
256+
* @param subjects
255257
* the subject
256258
*/
257-
public void setSubject(String subject) {
258-
this.subject = subject;
259+
public void setSubjects(List<String> subjects) {
260+
this.subjects = subjects;
261+
}
262+
263+
/**
264+
* Returns the series subject.
265+
*
266+
* @return the subject
267+
*/
268+
public List<String> getSubjects() {
269+
return subjects;
259270
}
260271

261272
/**
262273
* Returns the series subject.
263274
*
264275
* @return the subject
265276
*/
266-
public String getSubject() {
267-
return subject;
277+
@Deprecated
278+
private String getSubject() {
279+
return String.join(",", this.subjects);
280+
}
281+
282+
/**
283+
* Sets the series subject.
284+
*
285+
* @param subject the subject
286+
*/
287+
@XmlElement(name = "subject")
288+
@Deprecated
289+
private void setSubject(String subject) {
290+
if (this.subjects.isEmpty() && Objects.nonNull(subject)) {
291+
this.subjects.addAll(List.of(subject.split(",")));
292+
}
268293
}
269294

270295
/**

modules/elasticsearch-index/src/main/java/org/opencastproject/elasticsearch/index/objects/series/SeriesIndexUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public static SearchMetadataCollection toSearchMetadata(Series series) {
9090
if (StringUtils.trimToNull(series.getDescription()) != null) {
9191
metadata.addField(SeriesIndexSchema.DESCRIPTION, series.getDescription(), true);
9292
}
93-
if (StringUtils.trimToNull(series.getSubject()) != null) {
94-
metadata.addField(SeriesIndexSchema.SUBJECT, series.getSubject(), true);
93+
if (series.getSubjects() != null) {
94+
metadata.addField(SeriesIndexSchema.SUBJECT, series.getSubjects().toArray(), true);
9595
}
9696
if (StringUtils.trimToNull(series.getLanguage()) != null) {
9797
metadata.addField(SeriesIndexSchema.LANGUAGE, series.getLanguage(), false);

modules/elasticsearch-index/src/test/java/org/opencastproject/elasticsearch/index/objects/series/SeriesTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public class SeriesTest {
6262
private String id = "10.0000-1";
6363
private String title = "Land and Vegetation: Key players on the Climate Scene";
6464
private String description = "This is the description for this series.";
65-
private String subject = "This is the subject";
65+
private List<String> subjects = new ArrayList<>();
66+
private String subject1 = "This is the subject";
6667
private String organization = "Organization";
6768
private String language = "Klingon";
6869
private String creator = "Creator Name";
@@ -85,6 +86,9 @@ public class SeriesTest {
8586
@Before
8687
public void setUp() throws IOException, IllegalStateException, java.text.ParseException {
8788
createdDateTime = new Date(DateTimeSupport.fromUTC("2011-07-16T20:39:05Z"));
89+
// Setup subject collection
90+
subjects.add(subject1);
91+
subjects.add("This is another subject");
8892
// Setup presenter collection
8993
organizers.add(organizer1);
9094
organizers.add(organizer2);
@@ -100,11 +104,13 @@ public void setUp() throws IOException, IllegalStateException, java.text.ParseEx
100104

101105
@Test
102106
public void testToJson() throws ParseException {
107+
108+
103109
// Initialize series
104110
Series series = new Series(id, organization);
105111
series.setTitle(title);
106112
series.setDescription(description);
107-
series.setSubject(subject);
113+
series.setSubjects(subjects);
108114
series.setLanguage(language);
109115
series.setCreator(creator);
110116
series.setLicense(license);
@@ -123,7 +129,7 @@ public void testToJson() throws ParseException {
123129
assertEquals(id, seriesJsonObject.get(IDENTIFIER_JSON_KEY));
124130
assertEquals(title, seriesJsonObject.get(TITLE_JSON_KEY));
125131
assertEquals(description, seriesJsonObject.get(DESCRIPTION_JSON_KEY));
126-
assertEquals(subject, seriesJsonObject.get(SUBJECT_JSON_KEY));
132+
assertEquals(subjects, seriesJsonObject.get(SUBJECT_JSON_KEY));
127133
assertEquals(organization, seriesJsonObject.get(ORGANIZATION_JSON_KEY));
128134
assertEquals(language, seriesJsonObject.get(LANGUAGE_JSON_KEY));
129135
assertEquals(creator, seriesJsonObject.get(CREATOR_JSON_KEY));

modules/external-api/src/main/java/org/opencastproject/external/endpoint/SeriesEndpoint.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,6 @@ private Response queryResultToJson(SearchResult<Series> result, boolean includeA
365365

366366
for (SearchResultItem<Series> item : result.getItems()) {
367367
final Series s = item.getSource();
368-
JsonArray subjects;
369-
if (s.getSubject() == null) {
370-
subjects = new JsonArray();
371-
} else {
372-
subjects = splitSubjectIntoArray(s.getSubject());
373-
}
374368

375369
Date createdDate = s.getCreatedDateTime();
376370
JsonObject seriesJson = new JsonObject();
@@ -379,8 +373,8 @@ private Response queryResultToJson(SearchResult<Series> result, boolean includeA
379373
seriesJson.addProperty("title", s.getTitle());
380374
seriesJson.addProperty("creator", safeString(s.getCreator()));
381375
seriesJson.addProperty("created", createdDate != null ? toUTC(createdDate.getTime()) : "");
382-
seriesJson.add("subjects", subjects);
383376

377+
seriesJson.add("subjects", collectionToJsonArray(s.getSubjects()));
384378
seriesJson.add("contributors", collectionToJsonArray(s.getContributors()));
385379
seriesJson.add("organizers", collectionToJsonArray(s.getOrganizers()));
386380
seriesJson.add("publishers", collectionToJsonArray(s.getPublishers()));
@@ -452,12 +446,6 @@ public Response getSeries(@HeaderParam("Accept") String acceptHeader, @PathParam
452446
securityService.getUser());
453447
if (optSeries.isPresent()) {
454448
final Series s = optSeries.get();
455-
JsonArray subjects;
456-
if (s.getSubject() == null) {
457-
subjects = new JsonArray();
458-
} else {
459-
subjects = splitSubjectIntoArray(s.getSubject());
460-
}
461449
Date createdDate = s.getCreatedDateTime();
462450

463451
JsonObject responseContent = new JsonObject();
@@ -467,7 +455,7 @@ public Response getSeries(@HeaderParam("Accept") String acceptHeader, @PathParam
467455
responseContent.addProperty("title", s.getTitle());
468456
responseContent.addProperty("description", safeString(s.getDescription()));
469457
responseContent.addProperty("creator", safeString(s.getCreator()));
470-
responseContent.add("subjects", subjects);
458+
responseContent.add("subjects", collectionToJsonArray(s.getSubjects()));
471459
responseContent.addProperty("organization", s.getOrganization());
472460
responseContent.addProperty("created", createdDate != null ? toUTC(createdDate.getTime()) : "");
473461
responseContent.add("contributors", collectionToJsonArray(s.getContributors()));
@@ -604,7 +592,7 @@ private DublinCoreMetadataCollection getSeriesMetadata(Series series) {
604592
MetadataField subject = metadata.getOutputFields().get(DublinCore.PROPERTY_SUBJECT.getLocalName());
605593
metadata.removeField(subject);
606594
MetadataField newSubject = new MetadataField(subject);
607-
newSubject.setValue(series.getSubject());
595+
newSubject.setValue(series.getSubjects());
608596
metadata.addField(newSubject);
609597

610598
MetadataField description = metadata.getOutputFields().get(DublinCore.PROPERTY_DESCRIPTION.getLocalName());

modules/external-api/src/test/java/org/opencastproject/external/endpoint/TestSeriesEndpoint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.easymock.EasyMock;
5353
import org.junit.Ignore;
5454

55+
import java.util.Collections;
5556
import java.util.Date;
5657
import java.util.HashMap;
5758
import java.util.HashSet;
@@ -105,7 +106,7 @@ public TestSeriesEndpoint() throws Exception {
105106
Series series1 = new Series("4fd0ef66-aea5-4b7a-a62a-a4ada0eafd6f", "opencast");
106107
series1.setTitle("Via API");
107108
series1.setDescription("A series created over the external API");
108-
series1.setSubject("Topic");
109+
series1.setSubjects(Collections.singletonList("Topic"));
109110
series1.setCreator("Gracie Walsh");
110111
series1.setCreatedDateTime(new Date(1429175556000L));
111112
series1.addContributor("Nu'man Farooq Morcos");

modules/series-service-impl/src/main/java/org/opencastproject/series/impl/SeriesServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ private Function<Optional<Series>, Optional<Series>> getMetadataUpdateFunction(S
749749
Series series = seriesOpt.orElse(new Series(seriesId, orgId, securityService.getUser().getName()));
750750
series.setTitle(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
751751
series.setDescription(dc.getFirst(DublinCore.PROPERTY_DESCRIPTION));
752-
series.setSubject(dc.getFirst(DublinCore.PROPERTY_SUBJECT));
752+
series.setSubjects(dc.get(DublinCore.PROPERTY_SUBJECT, DublinCore.LANGUAGE_ANY));
753753
series.setLanguage(dc.getFirst(DublinCoreCatalog.PROPERTY_LANGUAGE));
754754
series.setLicense(dc.getFirst(DublinCoreCatalog.PROPERTY_LICENSE));
755755
series.setRightsHolder(dc.getFirst(DublinCore.PROPERTY_RIGHTS_HOLDER));

0 commit comments

Comments
 (0)