Revision 60560
Added by Konstantina Galouni about 3 years ago
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/utils/ManagerUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.data.claims.utils; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
|
|
6 |
import java.io.BufferedReader; |
|
7 |
import java.io.InputStreamReader; |
|
8 |
import java.io.StringReader; |
|
9 |
import java.net.HttpURLConnection; |
|
10 |
import java.net.URL; |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
public class ManagerUtils { |
|
14 |
private static String registryAPIForManagerEmails; |
|
15 |
private String id; |
|
16 |
private String email; |
|
17 |
private String name; |
|
18 |
private String memberSince; |
|
19 |
|
|
20 |
private final static Logger log = Logger.getLogger(ManagerUtils.class); |
|
21 |
|
|
22 |
public String getRegistryAPIForManagerEmails() { return registryAPIForManagerEmails; } |
|
23 |
public void setRegistryAPIForManagerEmails(String registryAPIForManagerEmails) { ManagerUtils.registryAPIForManagerEmails = registryAPIForManagerEmails; } |
|
24 |
|
|
25 |
public String getName() { |
|
26 |
return name; |
|
27 |
} |
|
28 |
public void setName(String name) { |
|
29 |
this.name = name; |
|
30 |
} |
|
31 |
|
|
32 |
public String getId() { |
|
33 |
return id; |
|
34 |
} |
|
35 |
|
|
36 |
public void setId(String id) { |
|
37 |
this.id = id; |
|
38 |
} |
|
39 |
|
|
40 |
public String getEmail() { |
|
41 |
return email; |
|
42 |
} |
|
43 |
|
|
44 |
public void setEmail(String email) { |
|
45 |
this.email = email; |
|
46 |
} |
|
47 |
|
|
48 |
public String getMemberSince() { |
|
49 |
return memberSince; |
|
50 |
} |
|
51 |
|
|
52 |
public void setMemberSince(String memberSince) { |
|
53 |
this.memberSince = memberSince; |
|
54 |
} |
|
55 |
|
|
56 |
public List<ManagerUtils> getManagersByEmail(String community) { |
|
57 |
String url = registryAPIForManagerEmails.replace("{community}", community); |
|
58 |
URL obj = null; |
|
59 |
String responseStr = null; |
|
60 |
log.debug("Registry url is " + url); |
|
61 |
|
|
62 |
try { |
|
63 |
obj = new URL(url); |
|
64 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
65 |
log.debug("Get manager emails from registry response code is: " + con.getResponseCode()); |
|
66 |
if (con.getResponseCode() != 200) { |
|
67 |
return null; |
|
68 |
} |
|
69 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
70 |
StringBuffer response = new StringBuffer(); |
|
71 |
String inputLine; |
|
72 |
while ((inputLine = in.readLine()) != null) { |
|
73 |
response.append(inputLine).append("\n"); |
|
74 |
} |
|
75 |
in.close(); |
|
76 |
responseStr = response.toString(); |
|
77 |
} catch (Exception e) { |
|
78 |
log.error("An error occured while trying to fetch manager emails from registry ", e); |
|
79 |
return null; |
|
80 |
} |
|
81 |
return json2ManagerUtils(responseStr); |
|
82 |
} |
|
83 |
|
|
84 |
class ManagersResponse { |
|
85 |
public List<ManagerUtils> response; |
|
86 |
|
|
87 |
public List<ManagerUtils> getResponse() { |
|
88 |
return response; |
|
89 |
} |
|
90 |
|
|
91 |
public void setResponse(List<ManagerUtils> response) { |
|
92 |
this.response = response; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
private List<ManagerUtils> json2ManagerUtils(String json){ |
|
97 |
|
|
98 |
log.debug("Try to create List<ManagerUtils> from json: "+json); |
|
99 |
if (json == null){ |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
103 |
BufferedReader br = new BufferedReader(new StringReader(json)); |
|
104 |
//convert the json string back to object |
|
105 |
Gson gson = new Gson(); |
|
106 |
ManagersResponse managersResponse = null; |
|
107 |
List<ManagerUtils> managerUtilsList = null; |
|
108 |
|
|
109 |
try { |
|
110 |
managersResponse = gson.fromJson(br, ManagersResponse.class); |
|
111 |
managerUtilsList = managersResponse.getResponse(); |
|
112 |
}catch(Exception e){ |
|
113 |
log.debug("Error in parsing json response. Given json is : "+json, e); |
|
114 |
return null; |
|
115 |
} |
|
116 |
|
|
117 |
log.debug("Original response.........: "+managersResponse.toString()); |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
return managerUtilsList; |
|
122 |
} |
|
123 |
} |
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/emailSender/EmailSender.java | ||
---|---|---|
6 | 6 |
import eu.dnetlib.data.claims.entity.Project; |
7 | 7 |
import eu.dnetlib.data.claims.handler.*; |
8 | 8 |
import eu.dnetlib.data.claims.utils.ClaimUtils; |
9 |
import eu.dnetlib.data.claims.utils.CommunityUtils; |
|
9 |
//import eu.dnetlib.data.claims.utils.CommunityUtils;
|
|
10 | 10 |
import eu.dnetlib.data.claims.sql.SQLStoreException; |
11 |
import eu.dnetlib.data.claims.utils.ManagerUtils; |
|
11 | 12 |
import org.apache.log4j.Logger; |
12 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
13 | 14 |
|
... | ... | |
36 | 37 |
@Autowired |
37 | 38 |
private String defaultFrequencyInHours; |
38 | 39 |
|
40 |
// @Autowired |
|
41 |
// private CommunityUtils communityUtils; |
|
42 |
|
|
39 | 43 |
@Autowired |
40 |
private CommunityUtils communityUtils;
|
|
44 |
private ManagerUtils managerUtils;
|
|
41 | 45 |
|
42 | 46 |
private static String manageCommunityUserNotificationsPage; |
43 | 47 |
private static String openaireProjectClaimsPage; |
... | ... | |
222 | 226 |
// Send emails to actual project managers instead of special recipients |
223 | 227 |
List<String> managers = null; |
224 | 228 |
try { |
225 |
CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(openaireId); |
|
226 |
managers = communityInfo.getManagers(); |
|
227 |
if(managers != null) { |
|
228 |
Iterator itr = managers.iterator(); |
|
229 |
//CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(openaireId); |
|
230 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmail(openaireId); |
|
231 |
//managers = communityInfo.getManagers(); |
|
232 |
if(managerUtils != null) { |
|
233 |
Iterator<ManagerUtils> itr = managerUtils.iterator(); |
|
229 | 234 |
while (itr.hasNext()) { |
230 |
String manager = (String) itr.next(); |
|
235 |
String manager = (String) itr.next().getEmail();
|
|
231 | 236 |
Notification notification = fetchNotificationHandler.fetchNotification(openaireId, manager); |
232 | 237 |
if (notification != null) { |
233 | 238 |
itr.remove(); |
234 | 239 |
} else { |
240 |
if(managers == null) { |
|
241 |
managers = new ArrayList<>(); |
|
242 |
} |
|
243 |
managers.add(manager); |
|
235 | 244 |
logger.debug("Sending email to community manager: "+ manager); |
236 | 245 |
} |
237 | 246 |
} |
... | ... | |
332 | 341 |
try { |
333 | 342 |
List<Notification> trueNotifications = fetchNotificationHandler.fetchTrueNotifications(); |
334 | 343 |
|
344 |
Map<String, List<String>> allManagers = new HashMap<>(); |
|
345 |
|
|
335 | 346 |
if(trueNotifications != null) { |
336 | 347 |
for(Notification notification : trueNotifications) { |
337 | 348 |
if (enabledCommunitiesList != null && enabledCommunitiesList.contains(notification.getOpenaireId())) { |
338 | 349 |
|
339 |
CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(notification.getOpenaireId()); |
|
340 |
List<String> managers = null; |
|
341 |
if (communityInfo != null) { |
|
342 |
managers = communityInfo.getManagers(); |
|
350 |
if(!allManagers.containsKey(notification.getOpenaireId())) { |
|
351 |
allManagers.put(notification.getOpenaireId(), new ArrayList()); |
|
352 |
|
|
353 |
// CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(notification.getOpenaireId()); |
|
354 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmail(notification.getOpenaireId()); |
|
355 |
|
|
356 |
// List<String> managers = null; |
|
357 |
if (managerUtils != null) { |
|
358 |
for (ManagerUtils manager : managerUtils) { |
|
359 |
allManagers.get(notification.getOpenaireId()).add(manager.getEmail()); |
|
360 |
} |
|
361 |
} |
|
343 | 362 |
} |
344 | 363 |
|
345 |
if (managers != null && managers.contains(notification.getUserMail())) { |
|
364 |
|
|
365 |
// if (managers != null && managers.contains(notification.getUserMail())) { |
|
366 |
if(allManagers.get(notification.getOpenaireId()).contains(notification.getUserMail())) { |
|
346 | 367 |
Date _dateTo = format.parse(dateTo); |
347 | 368 |
|
348 | 369 |
Date _last_interaction_date = notification.getDate(); |
... | ... | |
369 | 390 |
} |
370 | 391 |
|
371 | 392 |
notificationHandler.updateNotificationLastInteractionDate(notification.getOpenaireId(), notification.getUserMail(), _dateTo); |
393 |
} else { |
|
394 |
logger.debug("[no notification] User "+notification.getUserMail()+" got latest notification at "+last_interaction_date+" and has set frequency to: "+notification.getFrequency()); |
|
372 | 395 |
} |
396 |
} else { |
|
397 |
logger.debug("User "+notification.getUserMail()+" is not manager of community "+notification.getOpenaireId()); |
|
373 | 398 |
} |
374 | 399 |
} else { |
375 | 400 |
logger.debug("Community "+notification.getOpenaireId()+" is not enabled"); |
... | ... | |
553 | 578 |
EmailSender.notifyProjectManagers = notifyProjectManagers; |
554 | 579 |
} |
555 | 580 |
|
556 |
public void setCommunityUtils(CommunityUtils communityUtils) { |
|
557 |
this.communityUtils = communityUtils; |
|
581 |
// public void setCommunityUtils(CommunityUtils communityUtils) { |
|
582 |
// this.communityUtils = communityUtils; |
|
583 |
// } |
|
584 |
// |
|
585 |
// public CommunityUtils getCommunityUtils() { |
|
586 |
// return communityUtils; |
|
587 |
// } |
|
588 |
|
|
589 |
|
|
590 |
public ManagerUtils getManagerUtils() { |
|
591 |
return managerUtils; |
|
558 | 592 |
} |
559 | 593 |
|
560 |
public CommunityUtils getCommunityUtils() {
|
|
561 |
return communityUtils;
|
|
594 |
public void setManagerUtils(ManagerUtils managerUtils) {
|
|
595 |
this.managerUtils = managerUtils;
|
|
562 | 596 |
} |
563 | 597 |
} |
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/springContext-claims.properties | ||
---|---|---|
10 | 10 |
services.claims.db.password = snowflakes |
11 | 11 |
|
12 | 12 |
services.claims.communityAPI = https://dev-openaire.d4science.org/openaire/community/ |
13 |
services.claims.searchAPIUrl = http://services.openaire.eu:8480/search/ |
|
13 |
services.claims.registryAPIForManagerEmails = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email |
|
14 |
services.claims.searchAPIUrl = http://beta.services.openaire.eu:8480/search/ |
|
14 | 15 |
#email properties |
15 | 16 |
## EMAIL SETTINGS |
16 | 17 |
services.claims.mail.host = smtp.gmail.com |
... | ... | |
29 | 30 |
|
30 | 31 |
services.claims.results.pathToSaveRecord = /home/argirok/claims_www_last/records/ |
31 | 32 |
services.claims.reports.pathToSaveReport = /home/argirok/claims_www_last/reports/ |
33 |
#services.claims.results.pathToSaveRecord = /home/konstantina/claims-www-last/records/ |
|
34 |
#services.claims.reports.pathToSaveReport = /home/konstantina/claims-www-last/reports/ |
|
32 | 35 |
|
33 | 36 |
#old version |
34 | 37 |
#services.claims.directClaimAPIUrl = http://beta.services.openaire.eu:8280/is/mvc/api/publications |
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/springContext-claims.xml | ||
---|---|---|
117 | 117 |
<bean id="communityUtils" class="eu.dnetlib.data.claims.utils.CommunityUtils"> |
118 | 118 |
<property name="communityAPI" value="${services.claims.communityAPI}"/> |
119 | 119 |
</bean> |
120 |
<bean id="managerUtils" class="eu.dnetlib.data.claims.utils.ManagerUtils"> |
|
121 |
<property name="registryAPIForManagerEmails" value="${services.claims.registryAPIForManagerEmails}"/> |
|
122 |
</bean> |
|
120 | 123 |
|
121 | 124 |
<bean id="sqlStore" class="eu.dnetlib.data.claims.sql.SqlStore" init-method="init" destroy-method="destroy"> |
122 | 125 |
<property name="dbUser" value="${services.claims.db.username}"/> |
Also available in: Unified diff
[Trunk | Claims Service]:
1. ManagerUtils.java: [NEW] File for getting community managers from registry service added.
2. springContext-claims.properties: Property "services.claims.registryAPIForManagerEmails" added - URL of registry service for requesting community manager emails.
3. springContext-claims.xml: Created bean with id="managerUtils" and property with name="registryAPIForManagerEmails".
4. EmailSender.java:
a. Autowire ManagerUtils and not CommunityUtils to get community managers from registry service.
b. In method "notificationEmails_For_CommunityClaims()" request managers for each community only once.