Skip to content

Commit 63cbc9c

Browse files
committed
fix parsing after some change.
1 parent 5429291 commit 63cbc9c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/api/ldn/COARNotifyRelationshipAnnouncement.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import jakarta.json.Json;
2121
import jakarta.json.JsonObject;
2222
import jakarta.json.JsonObjectBuilder;
23+
import jakarta.json.JsonValue;
2324
import jakarta.ws.rs.BadRequestException;
2425

2526
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -73,12 +74,20 @@ public COARNotifyRelationshipAnnouncement(
7374
*/
7475
public void processMessage(JsonObject msgObject) {
7576
// Extract subject, object, and relationship from the message
76-
String subjectId = extractField(msgObject, subjectKey);
77-
String objectId = extractField(msgObject, objectKey);
78-
String relationshipId = extractField(msgObject, relationshipKey);
77+
String subjectId;
78+
String objectId;
79+
String relationshipId;
80+
try {
81+
// Extract subject, object, and relationship from the message
82+
subjectId = extractField(msgObject, subjectKey);
83+
objectId = extractField(msgObject, objectKey);
84+
relationshipId = extractField(msgObject, relationshipKey);
7985

80-
if (subjectId == null || objectId == null || relationshipId == null) {
81-
throw new BadRequestException("Can't find the subject, relationship or object in the message - ignoring");
86+
if (subjectId == null || objectId == null || relationshipId == null) {
87+
throw new BadRequestException("Can't find the subject, relationship or object in the message - ignoring");
88+
}
89+
} catch (Exception e) {
90+
throw new BadRequestException("Failed to parse subject, relationship or object from the message - ignoring", e);
8291
}
8392

8493
// Get metadata about the citing resource
@@ -112,7 +121,15 @@ public void processMessage(JsonObject msgObject) {
112121
* Extract a field value from the message object.
113122
*/
114123
private String extractField(JsonObject msgObject, String key) {
115-
return msgObject.containsKey(key) ? msgObject.getString(key) : null;
124+
if (msgObject.containsKey(key)) {
125+
JsonValue value = msgObject.get(key);
126+
if (value.getValueType() == JsonValue.ValueType.OBJECT) {
127+
return ((JsonObject) value).getString("@id", null);
128+
} else if (value.getValueType() == JsonValue.ValueType.STRING) {
129+
return msgObject.getString(key);
130+
}
131+
}
132+
return null;
116133
}
117134

118135
/**

0 commit comments

Comments
 (0)