Skip to content

Commit ce64be3

Browse files
committed
Fixes external api subject field
The subject field of the external api had a custom type iterable_text, this is now replaced with mixed_text.
1 parent 377022b commit ce64be3

File tree

14 files changed

+47
-28
lines changed

14 files changed

+47
-28
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SeriesTest {
5656
private static final String ORGANIZERS_JSON_KEY = "organizers";
5757
private static final String ORGANIZER_JSON_KEY = "organizer";
5858
private static final String SERIES_JSON_KEY = "series";
59-
private static final String SUBJECT_JSON_KEY = "subject";
59+
private static final String SUBJECTS_JSON_KEY = "subjects";
6060
private static final String TITLE_JSON_KEY = "title";
6161

6262
private String id = "10.0000-1";
@@ -129,7 +129,7 @@ public void testToJson() throws ParseException {
129129
assertEquals(id, seriesJsonObject.get(IDENTIFIER_JSON_KEY));
130130
assertEquals(title, seriesJsonObject.get(TITLE_JSON_KEY));
131131
assertEquals(description, seriesJsonObject.get(DESCRIPTION_JSON_KEY));
132-
assertEquals(subjects, seriesJsonObject.get(SUBJECT_JSON_KEY));
132+
assertEquals(subjects, seriesJsonObject.get(SUBJECTS_JSON_KEY));
133133
assertEquals(organization, seriesJsonObject.get(ORGANIZATION_JSON_KEY));
134134
assertEquals(language, seriesJsonObject.get(LANGUAGE_JSON_KEY));
135135
assertEquals(creator, seriesJsonObject.get(CREATOR_JSON_KEY));

modules/elasticsearch-index/src/test/resources/adminui_event_metadata.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
},
88
"end_date":"2008-03-16T14:00:00Z",
99
"title":"Land and Vegetation: Key players on the Climate Scene",
10-
"subject": ["This is the subject"],
10+
"subjects": [
11+
"This is the subject",
12+
"This is another subject"
13+
],
1114
"description":"This is the description for this event.",
1215
"publications":{
1316
"engage":"engage.html?e=p-1",

modules/elasticsearch-index/src/test/resources/adminui_series_metadata.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
},
88
"end_date":"2008-03-16T14:00:00Z",
99
"title":"Land and Vegetation: Key players on the Climate Scene",
10-
"subject":["This is the subject"],
10+
"subjects":[
11+
"This is the subject",
12+
"This is another subject"
13+
],
1114
"description":"This is the description for this series.",
1215
"publications":{
1316
"engage":"engage.html?e=p-1",

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,9 +1787,17 @@ public Response updateEventMetadataByType(@HeaderParam("Accept") String acceptHe
17871787
return error.get();
17881788
}
17891789
collection.removeField(field);
1790-
JSONArray subjectArray = (JSONArray) parser.parse(updatedFields.get(key));
1791-
collection.addField(
1792-
MetadataJson.copyWithDifferentJsonValue(field, StringUtils.join(subjectArray.iterator(), ",")));
1790+
collection.addField(MetadataJson.copyWithDifferentJsonValue(field, updatedFields.get(key)));
1791+
} else if ("subject".equals(key)) {
1792+
MetadataField field = collection.getOutputFields().get(DublinCore.PROPERTY_SUBJECT.getLocalName());
1793+
Optional<Response> error = validateField(field, key, id, type, updatedFields);
1794+
if (error.isPresent()) {
1795+
return error.get();
1796+
}
1797+
collection.removeField(field);
1798+
JSONArray a = new JSONArray();
1799+
a.addAll(List.of(updatedFields.get(key).split(",")));
1800+
collection.addField(MetadataJson.copyWithDifferentJsonValue(field, a.toJSONString()));
17931801
} else if ("startDate".equals(key)) {
17941802
// Special handling for start date since in API v1 we expect start date and start time to be separate fields.
17951803
MetadataField field = collection.getOutputFields().get(key);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,18 @@ public Response updateSeriesMetadata(@HeaderParam("Accept") String acceptHeader,
798798
"The series metadata field with id '%s' and the metadata type '%s' is required and can not be empty!.",
799799
key, type));
800800
}
801-
collection.removeField(field);
802-
collection.addField(MetadataJson.copyWithDifferentJsonValue(field, updatedFields.get(key)));
801+
if ("subject".equals(key)) {
802+
collection.removeField(field);
803+
JsonArray subjects = splitSubjectIntoArray(updatedFields.get(key));
804+
collection.addField(MetadataJson.copyWithDifferentJsonValue(
805+
field,
806+
subjects.toString()
807+
)
808+
);
809+
} else {
810+
collection.removeField(field);
811+
collection.addField(MetadataJson.copyWithDifferentJsonValue(field, updatedFields.get(key)));
812+
}
803813
}
804814

805815
metadataList.add(adapter, collection);

modules/external-api/src/main/java/org/opencastproject/external/util/ExternalMetadataUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public static void changeSubjectToSubjects(final DublinCoreMetadataCollection co
4343
final MetadataField subject = collection.getOutputFields().get(DublinCore.PROPERTY_SUBJECT.getLocalName());
4444
collection.removeField(subject);
4545
final List<String> newValue;
46-
if (subject.getValue() != null) {
46+
if (subject.getValue() != null && subject.getValue() instanceof String) {
4747
newValue = Pattern.compile(",").splitAsStream(subject.getValue().toString()).collect(Collectors.toList());
48+
} else if (subject.getValue() != null && subject.getValue() instanceof List) {
49+
newValue = (List<String>)subject.getValue();
4850
} else {
4951
newValue = null;
5052
}
@@ -56,7 +58,7 @@ public static void changeSubjectToSubjects(final DublinCoreMetadataCollection co
5658
subject.isRequired(),
5759
newValue,
5860
subject.isTranslatable(),
59-
MetadataField.Type.ITERABLE_TEXT,
61+
MetadataField.Type.MIXED_TEXT,
6062
subject.getCollection(),
6163
subject.getCollectionID(),
6264
subject.getOrder(),

modules/external-api/src/test/resources/episode-catalog.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ property.contributors.order=8
6363
# Subject
6464
property.subject.inputID=subject
6565
property.subject.label=EVENTS.EVENTS.DETAILS.METADATA.SUBJECT
66-
property.subject.type=text
66+
property.subject.type=mixed_text
6767
property.subject.readOnly=false
6868
property.subject.required=false
6969
property.subject.order=1

modules/external-api/src/test/resources/event-metadata-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"readOnly": false,
1616
"id": "subjects",
1717
"label": "EVENTS.EVENTS.DETAILS.METADATA.SUBJECT",
18-
"type": "text",
18+
"type": "mixed_text",
1919
"value": [],
2020
"required": false
2121
},

modules/external-api/src/test/resources/event-metadata-update-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"readOnly": false,
1212
"id": "subject",
1313
"label": "EVENTS.EVENTS.DETAILS.METADATA.SUBJECT",
14-
"type": "text",
15-
"value": "What this is about - edited",
14+
"type": "mixed_text",
15+
"value": ["What this is about - edited"],
1616
"required": false
1717
},
1818
{

modules/external-api/src/test/resources/event-update-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"readOnly": false,
1616
"id": "subject",
1717
"label": "EVENTS.EVENTS.DETAILS.METADATA.SUBJECT",
18-
"type": "text",
19-
"value": "updated subject 1,updated subject 2",
18+
"type": "mixed_text",
19+
"value": ["updated subject 1","updated subject 2"],
2020
"required": false
2121
},
2222
{

0 commit comments

Comments
 (0)