|
4 | 4 | import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; |
5 | 5 | import edu.harvard.iq.dataverse.branding.BrandingUtil; |
6 | 6 | import edu.harvard.iq.dataverse.util.SystemConfig; |
| 7 | + |
7 | 8 | import jakarta.ejb.EJB; |
8 | 9 | import jakarta.ejb.Stateless; |
| 10 | +import jakarta.json.Json; |
| 11 | +import jakarta.json.JsonException; |
| 12 | +import jakarta.json.JsonReader; |
| 13 | +import jakarta.json.JsonValue; |
| 14 | + |
| 15 | +import java.io.StringReader; |
9 | 16 |
|
10 | 17 | import static edu.harvard.iq.dataverse.dataset.DatasetUtil.getLocaleCurationStatusLabel; |
11 | 18 | import static edu.harvard.iq.dataverse.util.json.JsonPrinter.jsonRoleAssignments; |
@@ -80,8 +87,6 @@ public void addFieldsByType(final NullSafeJsonBuilder notificationJson, final Au |
80 | 87 | addRequestFileAccessFields(notificationJson, userNotification, requestor); |
81 | 88 | break; |
82 | 89 | case REQUESTEDFILEACCESS: |
83 | | - case GRANTFILEACCESS: |
84 | | - case REJECTFILEACCESS: |
85 | 90 | addDataFileFields(notificationJson, userNotification); |
86 | 91 | break; |
87 | 92 | case DATASETCREATED: |
@@ -116,6 +121,8 @@ public void addFieldsByType(final NullSafeJsonBuilder notificationJson, final Au |
116 | 121 | case GLOBUSUPLOADLOCALFAILURE: |
117 | 122 | case GLOBUSDOWNLOADCOMPLETEDWITHERRORS: |
118 | 123 | case CHECKSUMFAIL: |
| 124 | + case GRANTFILEACCESS: |
| 125 | + case REJECTFILEACCESS: |
119 | 126 | addDatasetFields(notificationJson, userNotification); |
120 | 127 | break; |
121 | 128 | case INGESTCOMPLETED: |
@@ -184,6 +191,8 @@ private void addDataFileFields(final NullSafeJsonBuilder notificationJson, final |
184 | 191 | if (dataFile != null) { |
185 | 192 | notificationJson.add(KEY_DATAFILE_ID, dataFile.getId()); |
186 | 193 | notificationJson.add(KEY_DATAFILE_DISPLAY_NAME, dataFile.getDisplayName()); |
| 194 | + notificationJson.add(KEY_DATASET_DISPLAY_NAME, dataFile.getOwner().getDisplayName()); |
| 195 | + notificationJson.add(KEY_DATASET_PERSISTENT_ID, dataFile.getOwner().getGlobalId().asString()); |
187 | 196 | } else { |
188 | 197 | notificationJson.add(KEY_OBJECT_DELETED, true); |
189 | 198 | } |
@@ -260,6 +269,24 @@ private void addIngestFields(final NullSafeJsonBuilder notificationJson, final U |
260 | 269 |
|
261 | 270 | private void addDatasetMentionedFields(final NullSafeJsonBuilder notificationJson, final UserNotification userNotification) { |
262 | 271 | addDatasetFields(notificationJson, userNotification); |
263 | | - notificationJson.add(KEY_ADDITIONAL_INFO, userNotification.getAdditionalInfo()); |
| 272 | + |
| 273 | + final String additionalInfo = userNotification.getAdditionalInfo(); |
| 274 | + |
| 275 | + if (additionalInfo != null && !additionalInfo.isEmpty()) { |
| 276 | + try (StringReader stringReader = new StringReader(additionalInfo); |
| 277 | + JsonReader jsonReader = Json.createReader(stringReader)) { |
| 278 | + |
| 279 | + // Try to parse the string into a JSON value |
| 280 | + JsonValue additionalInfoJson = jsonReader.readValue(); |
| 281 | + |
| 282 | + // If successful, add the parsed JSON value. |
| 283 | + notificationJson.add(KEY_ADDITIONAL_INFO, additionalInfoJson); |
| 284 | + |
| 285 | + } catch (JsonException e) { |
| 286 | + // If parsing fails, it's not a valid JSON string. |
| 287 | + // Fall back to adding it as a simple string. |
| 288 | + notificationJson.add(KEY_ADDITIONAL_INFO, additionalInfo); |
| 289 | + } |
| 290 | + } |
264 | 291 | } |
265 | 292 | } |
0 commit comments