Skip to content

Commit 80e84c3

Browse files
${PD-1935} Member name fix for MVP Notifications (#7342)
1 parent b7fc66c commit 80e84c3

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

orcid-scheduler-web/src/main/java/org/orcid/scheduler/mvp/OrcidIntegrationMVPNotifications.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.json.JSONArray;
1111
import org.orcid.core.manager.ProfileEntityCacheManager;
1212
import org.orcid.core.manager.v3.NotificationManager;
13+
import org.orcid.core.manager.v3.RecordNameManager;
14+
import org.orcid.jaxb.model.v3.release.record.Name;
1315
import org.orcid.persistence.dao.ClientDetailsDao;
1416
import org.orcid.persistence.dao.OrcidOauth2TokenDetailDao;
1517
import org.orcid.persistence.dao.ProfileEmailDomainDao;
@@ -42,9 +44,19 @@ public class OrcidIntegrationMVPNotifications {
4244

4345
@Resource(name = "orcidOauth2TokenDetailDaoReadOnly")
4446
private OrcidOauth2TokenDetailDao orcidOauth2TokenDetailDaoReadOnly;
45-
46-
@Resource
47-
private ProfileEntityCacheManager profileEntityCacheManager;
47+
48+
@Resource(name = "recordNameManagerV3")
49+
private RecordNameManager recordNameManager;
50+
51+
/**
52+
* Creates notifications for clients that have enabled the MVP feature
53+
*
54+
* This method checks for clients that have the MVP feature enabled and
55+
* sends notifications to users whose email domains match the configured
56+
* domains for each client. Notifications are sent only if no previous
57+
* notifications have been sent or no notification sent within a specified
58+
* number of days by default 10.
59+
*/
4860

4961
public void createOrcidIntegrationNotifications() {
5062
// Get clients eligible for mvp
@@ -55,12 +67,16 @@ public void createOrcidIntegrationNotifications() {
5567
for (ClientDetailsEntity clientDetails : clientsWithMVP) {
5668
if (StringUtils.isNotBlank(clientDetails.getNotificationWebpageUrl()) && StringUtils.isNotBlank(clientDetails.getNotificationDomains())) {
5769
long startTimeClient = System.currentTimeMillis();
58-
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(clientDetails.getGroupProfileId());
59-
String memberName = profileEntity != null ? profileEntity.getUsername() : null;
60-
if (memberName == null || memberName.isEmpty()) {
70+
Name memberNameObj = recordNameManager.getRecordName(clientDetails.getGroupProfileId());
71+
String memberName = null;
72+
if (memberNameObj != null) {
73+
memberName = memberNameObj.getCreditName() != null ? memberNameObj.getCreditName().getContent() : null;
74+
}
75+
76+
if (memberName == null) {
6177
memberName = clientDetails.getClientName();
6278
}
63-
79+
6480
LOG.info("Start process client {}. Notification send for the second time if no notifications sent since {} ago", clientDetails.getClientId(),
6581
daysAgo);
6682
try {
@@ -74,7 +90,7 @@ public void createOrcidIntegrationNotifications() {
7490
}
7591
}
7692
if (profileDomainSet.size() > 0) {
77-
93+
7894
for (ProfileEmailDomainEntity pe : profileDomainSet) {
7995
if (!orcidOauth2TokenDetailDaoReadOnly.hasTokenForClient(pe.getOrcid(), clientDetails.getClientId())) {
8096
List<NotificationEntity> orcidIntegrationNotifications = notificationManager.findByOrcidAndClientAndNotificationFamilyNoClientToken(
@@ -118,19 +134,17 @@ private String durationToString(long durationMillis) {
118134
long seconds = (durationMillis / 1000) % 60;
119135
return String.format("%d hours, %d minutes, %d seconds", hours, minutes, seconds);
120136
}
121-
122-
137+
123138
private boolean shouldSendNotification(List<NotificationEntity> orcidIntegrationNotifications) {
124139
if (orcidIntegrationNotifications == null || orcidIntegrationNotifications.isEmpty()) {
125140
return true;
126141
}
127-
128-
if (orcidIntegrationNotifications.size() > 1) {
129-
return false ;
130-
}
131-
else {
132-
java.util.Date daysAgoDate = new java.util.Date(System.currentTimeMillis() - daysAgo * 24 * 60 * 60 * 1000);
133-
return orcidIntegrationNotifications.get(0).getDateCreated() != null && orcidIntegrationNotifications.get(0).getDateCreated().before(daysAgoDate);
142+
143+
if (orcidIntegrationNotifications.size() > 1) {
144+
return false;
145+
} else {
146+
java.util.Date daysAgoDate = new java.util.Date(System.currentTimeMillis() - daysAgo * 24 * 60 * 60 * 1000);
147+
return orcidIntegrationNotifications.get(0).getDateCreated() != null && orcidIntegrationNotifications.get(0).getDateCreated().before(daysAgoDate);
134148
}
135149
}
136150
}

0 commit comments

Comments
 (0)