From 72db330c1d9c9a8ce664ae44e686d4aa989bf63f Mon Sep 17 00:00:00 2001 From: chenganj Date: Mon, 26 Sep 2022 15:51:31 -0400 Subject: [PATCH 1/3] license internationalization - first commit --- .../harvard/iq/dataverse/util/MailUtil.java | 26 +++++++++++-------- src/main/java/propertyFiles/Bundle.properties | 20 +++++++------- .../iq/dataverse/util/MailUtilTest.java | 16 +++++++++--- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java b/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java index 55c6f4d83d6..a2c4039f04c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java @@ -32,6 +32,10 @@ public static InternetAddress parseSystemAddress(String systemEmail) { public static String getSubjectTextBasedOnNotification(UserNotification userNotification, Object objectOfNotification) { List rootDvNameAsList = Arrays.asList(BrandingUtil.getInstallationBrandName()); + String datasetDisplayName = ""; + if (objectOfNotification != null) { + datasetDisplayName = ((Dataset)objectOfNotification).getDisplayName(); + } switch (userNotification.getType()) { case ASSIGNROLE: return BundleUtil.getStringFromBundle("notification.email.assign.role.subject", rootDvNameAsList); @@ -46,23 +50,23 @@ public static String getSubjectTextBasedOnNotification(UserNotification userNoti case REJECTFILEACCESS: return BundleUtil.getStringFromBundle("notification.email.rejected.file.access.subject", rootDvNameAsList); case DATASETCREATED: - return BundleUtil.getStringFromBundle("notification.email.dataset.created.subject", Arrays.asList(rootDvNameAsList.get(0), ((Dataset)objectOfNotification).getDisplayName())); + return BundleUtil.getStringFromBundle("notification.email.dataset.created.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case CREATEDS: - return BundleUtil.getStringFromBundle("notification.email.create.dataset.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.create.dataset.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case SUBMITTEDDS: - return BundleUtil.getStringFromBundle("notification.email.submit.dataset.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.submit.dataset.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case PUBLISHEDDS: - return BundleUtil.getStringFromBundle("notification.email.publish.dataset.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.publish.dataset.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case PUBLISHFAILED_PIDREG: - return BundleUtil.getStringFromBundle("notification.email.publishFailure.dataset.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.publishFailure.dataset.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case RETURNEDDS: - return BundleUtil.getStringFromBundle("notification.email.returned.dataset.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.returned.dataset.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case WORKFLOW_SUCCESS: - return BundleUtil.getStringFromBundle("notification.email.workflow.success.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.workflow.success.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case WORKFLOW_FAILURE: - return BundleUtil.getStringFromBundle("notification.email.workflow.failure.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.workflow.failure.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case STATUSUPDATED: - return BundleUtil.getStringFromBundle("notification.email.status.change.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.status.change.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case CREATEACC: return BundleUtil.getStringFromBundle("notification.email.create.account.subject", rootDvNameAsList); case CHECKSUMFAIL: @@ -83,9 +87,9 @@ public static String getSubjectTextBasedOnNotification(UserNotification userNoti case APIGENERATED: return BundleUtil.getStringFromBundle("notification.email.apiTokenGenerated.subject", rootDvNameAsList); case INGESTCOMPLETED: - return BundleUtil.getStringFromBundle("notification.email.ingestCompleted.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.ingestCompleted.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); case INGESTCOMPLETEDWITHERRORS: - return BundleUtil.getStringFromBundle("notification.email.ingestCompletedWithErrors.subject", rootDvNameAsList); + return BundleUtil.getStringFromBundle("notification.email.ingestCompletedWithErrors.subject", Arrays.asList(rootDvNameAsList.get(0), datasetDisplayName)); } return ""; } diff --git a/src/main/java/propertyFiles/Bundle.properties b/src/main/java/propertyFiles/Bundle.properties index 5035325ee8d..32ae282edc2 100644 --- a/src/main/java/propertyFiles/Bundle.properties +++ b/src/main/java/propertyFiles/Bundle.properties @@ -686,28 +686,28 @@ dashboard.card.datamove.dataset.command.error.indexingProblem=Dataset could not #MailServiceBean.java notification.email.create.dataverse.subject={0}: Your dataverse has been created -notification.email.create.dataset.subject={0}: Your dataset has been created +notification.email.create.dataset.subject={0}: Dataset "{1}" has been created notification.email.dataset.created.subject={0}: Dataset "{1}" has been created notification.email.request.file.access.subject={0}: Access has been requested for a restricted file notification.email.grant.file.access.subject={0}: You have been granted access to a restricted file notification.email.rejected.file.access.subject={0}: Your request for access to a restricted file has been rejected -notification.email.submit.dataset.subject={0}: Your dataset has been submitted for review -notification.email.publish.dataset.subject={0}: Your dataset has been published -notification.email.publishFailure.dataset.subject={0}: Failed to publish your dataset -notification.email.returned.dataset.subject={0}: Your dataset has been returned -notification.email.workflow.success.subject={0}: Your dataset has been processed +notification.email.submit.dataset.subject={0}: Dataset "{1}" has been submitted for review +notification.email.publish.dataset.subject={0}: Dataset "{1}" has been published +notification.email.publishFailure.dataset.subject={0}: Failed to publish your dataset "{1}" +notification.email.returned.dataset.subject={0}: Dataset "{1}" has been returned +notification.email.workflow.success.subject={0}: Dataset "{1}" has been processed notification.email.workflow.success=A workflow running on {0} (view at {1} ) succeeded: {2} -notification.email.workflow.failure.subject={0}: Failed to process your dataset +notification.email.workflow.failure.subject={0}: Failed to process your dataset "{1}" notification.email.workflow.failure=A workflow running on {0} (view at {1} ) failed: {2} -notification.email.status.change.subject={0}: Dataset Status Change +notification.email.status.change.subject={0}: Dataset "{1}" Status Change notification.email.status.change=The Status of the dataset ({0}) has changed to {1} notification.email.workflow.nullMessage=No additional message sent from the workflow. notification.email.create.account.subject={0}: Your account has been created notification.email.assign.role.subject={0}: You have been assigned a role notification.email.revoke.role.subject={0}: Your role has been revoked notification.email.verifyEmail.subject={0}: Verify your email address -notification.email.ingestCompleted.subject={0}: Dataset status -notification.email.ingestCompletedWithErrors.subject={0}: Dataset status +notification.email.ingestCompleted.subject={0}: Dataset "{1}" status +notification.email.ingestCompletedWithErrors.subject={0}: Dataset "{1}" status notification.email.greeting=Hello, \n notification.email.greeting.html=Hello,
# Bundle file editors, please note that "notification.email.welcome" is used in a unit test diff --git a/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java b/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java index 4363d1dd3c9..61024328bd1 100644 --- a/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java @@ -98,25 +98,33 @@ public void testSubjectRejectFileAccess() { @Test public void testSubjectCreateDataset() { userNotification.setType(UserNotification.Type.CREATEDS); - assertEquals("LibraScholar: Your dataset has been created", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); + String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; + System.out.println((" JAYANTHY 1=============== " + output )); + assertEquals("LibraScholar: Dataset \"\" has been created", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectSubmittedDS() { userNotification.setType(UserNotification.Type.SUBMITTEDDS); - assertEquals("LibraScholar: Your dataset has been submitted for review", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); + String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; + System.out.println((" JAYANTHY 2=============== " + output )); + assertEquals("LibraScholar: Dataset \"\" has been submitted for review", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectPublishedDS() { userNotification.setType(UserNotification.Type.PUBLISHEDDS); - assertEquals("LibraScholar: Your dataset has been published", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); + String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; + System.out.println((" JAYANTHY 3=============== " + output )); + assertEquals("LibraScholar: Dataset \"\" has been published", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectReturnedDS() { userNotification.setType(UserNotification.Type.RETURNEDDS); - assertEquals("LibraScholar: Your dataset has been returned", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); + String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; + System.out.println((" JAYANTHY 4=============== " + output )); + assertEquals("LibraScholar: Dataset \"\" has been returned", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test From c807811d3780c02f81435e736e2d98b2a027d0c2 Mon Sep 17 00:00:00 2001 From: chenganj Date: Wed, 12 Oct 2022 13:41:32 -0400 Subject: [PATCH 2/3] removed comments --- .../java/edu/harvard/iq/dataverse/util/MailUtilTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java b/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java index 61024328bd1..76e447b3faa 100644 --- a/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java @@ -98,32 +98,24 @@ public void testSubjectRejectFileAccess() { @Test public void testSubjectCreateDataset() { userNotification.setType(UserNotification.Type.CREATEDS); - String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; - System.out.println((" JAYANTHY 1=============== " + output )); assertEquals("LibraScholar: Dataset \"\" has been created", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectSubmittedDS() { userNotification.setType(UserNotification.Type.SUBMITTEDDS); - String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; - System.out.println((" JAYANTHY 2=============== " + output )); assertEquals("LibraScholar: Dataset \"\" has been submitted for review", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectPublishedDS() { userNotification.setType(UserNotification.Type.PUBLISHEDDS); - String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; - System.out.println((" JAYANTHY 3=============== " + output )); assertEquals("LibraScholar: Dataset \"\" has been published", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } @Test public void testSubjectReturnedDS() { userNotification.setType(UserNotification.Type.RETURNEDDS); - String output = MailUtil.getSubjectTextBasedOnNotification(userNotification, null) ; - System.out.println((" JAYANTHY 4=============== " + output )); assertEquals("LibraScholar: Dataset \"\" has been returned", MailUtil.getSubjectTextBasedOnNotification(userNotification, null)); } From 3d621abf192e85333b7091f0d1a41273f0b7090e Mon Sep 17 00:00:00 2001 From: chenganj Date: Wed, 26 Oct 2022 14:39:29 -0400 Subject: [PATCH 3/3] handled class cast exception --- src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java b/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java index ffb435feed2..d64a1f7cce1 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java @@ -33,9 +33,11 @@ public static InternetAddress parseSystemAddress(String systemEmail) { public static String getSubjectTextBasedOnNotification(UserNotification userNotification, Object objectOfNotification) { List rootDvNameAsList = Arrays.asList(BrandingUtil.getInstallationBrandName()); String datasetDisplayName = ""; - if (objectOfNotification != null) { + + if (objectOfNotification != null && (objectOfNotification instanceof Dataset) ) { datasetDisplayName = ((Dataset)objectOfNotification).getDisplayName(); } + switch (userNotification.getType()) { case ASSIGNROLE: return BundleUtil.getStringFromBundle("notification.email.assign.role.subject", rootDvNameAsList);