Revision 62369
Added by Argiro Kokogiannaki over 1 year ago
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/entity/Notification.java | ||
---|---|---|
55 | 55 |
public void setDate(Date last_interaction_date) { |
56 | 56 |
this.last_interaction_date = last_interaction_date; |
57 | 57 |
} |
58 |
|
|
59 |
@Override |
|
60 |
public String toString() { |
|
61 |
return "Notification{" + |
|
62 |
"openaireId='" + openaireId + '\'' + |
|
63 |
", openaireName='" + openaireName + '\'' + |
|
64 |
", userMail='" + userMail + '\'' + |
|
65 |
", frequency=" + frequency + |
|
66 |
", notify=" + notify + |
|
67 |
", last_interaction_date=" + last_interaction_date + |
|
68 |
'}'; |
|
69 |
} |
|
58 | 70 |
} |
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/utils/ManagerUtils.java | ||
---|---|---|
8 | 8 |
import java.io.StringReader; |
9 | 9 |
import java.net.HttpURLConnection; |
10 | 10 |
import java.net.URL; |
11 |
import java.util.Arrays; |
|
11 | 12 |
import java.util.List; |
12 | 13 |
|
13 | 14 |
public class ManagerUtils { |
14 | 15 |
private static String registryAPIForManagerEmails; |
15 |
private static String closedRegistryAPIForManagerEmails; |
|
16 |
private static String sessionCookieName; |
|
17 |
private static String sessionCookieDomain; |
|
18 | 16 |
private String id; |
19 | 17 |
private String email; |
20 | 18 |
private String name; |
... | ... | |
56 | 54 |
this.memberSince = memberSince; |
57 | 55 |
} |
58 | 56 |
|
59 |
public static String getSessionCookieName() { |
|
60 |
return sessionCookieName; |
|
61 |
} |
|
62 |
|
|
63 |
public static void setSessionCookieName(String sessionCookieName) { |
|
64 |
ManagerUtils.sessionCookieName = sessionCookieName; |
|
65 |
} |
|
66 |
|
|
67 |
public static String getSessionCookieDomain() { |
|
68 |
return sessionCookieDomain; |
|
69 |
} |
|
70 |
|
|
71 |
public static void setSessionCookieDomain(String sessionCookieDomain) { |
|
72 |
ManagerUtils.sessionCookieDomain = sessionCookieDomain; |
|
73 |
} |
|
74 |
|
|
75 |
public static String getClosedRegistryAPIForManagerEmails() { |
|
76 |
return closedRegistryAPIForManagerEmails; |
|
77 |
} |
|
78 |
|
|
79 |
public static void setClosedRegistryAPIForManagerEmails(String closedRegistryAPIForManagerEmails) { |
|
80 |
ManagerUtils.closedRegistryAPIForManagerEmails = closedRegistryAPIForManagerEmails; |
|
81 |
} |
|
82 |
|
|
83 |
public List<ManagerUtils> getManagersByEmail(String community, String sessionId) { |
|
57 |
public List<ManagerUtils> getManagersByEmail(String community) { |
|
84 | 58 |
String url = registryAPIForManagerEmails.replace("{community}", community); |
85 |
URL obj = null; |
|
86 |
String responseStr = null; |
|
87 |
log.debug("Registry url is " + url); |
|
88 | 59 |
|
89 |
try { |
|
90 |
obj = new URL(url); |
|
91 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
92 |
con.setRequestProperty("Cookie",sessionCookieName + "="+sessionId + "; domain="+ sessionCookieDomain+"; path=/;"); |
|
93 |
log.debug("Get manager emails from registry response code is: " + con.getResponseCode()); |
|
94 |
if (con.getResponseCode() != 200) { |
|
95 |
return null; |
|
96 |
} |
|
97 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
98 |
StringBuffer response = new StringBuffer(); |
|
99 |
String inputLine; |
|
100 |
while ((inputLine = in.readLine()) != null) { |
|
101 |
response.append(inputLine).append("\n"); |
|
102 |
} |
|
103 |
in.close(); |
|
104 |
responseStr = response.toString(); |
|
105 |
} catch (Exception e) { |
|
106 |
log.error("An error occured while trying to fetch manager emails from registry ", e); |
|
107 |
return null; |
|
108 |
} |
|
109 |
return json2ManagerUtils(responseStr); |
|
110 |
} |
|
111 |
public List<ManagerUtils> getManagersByEmailNoSession(String community) { |
|
112 |
String url = "http://mpagasas.di.uoa.gr:8080/dnet-role-management/admin/community/"+community+"?name=false"; |
|
113 | 60 |
URL obj = null; |
114 | 61 |
String responseStr = null; |
115 | 62 |
log.debug("Registry url is " + url); |
... | ... | |
162 | 109 |
List<ManagerUtils> managerUtilsList = null; |
163 | 110 |
|
164 | 111 |
try { |
165 |
managersResponse = gson.fromJson(br, ManagersResponse.class);
|
|
166 |
managerUtilsList = managersResponse.getResponse();
|
|
167 |
}catch(Exception e){
|
|
112 |
ManagerUtils[] testCase = gson.fromJson(br, ManagerUtils[].class);
|
|
113 |
managerUtilsList = Arrays.asList(testCase);
|
|
114 |
}catch(Throwable e){
|
|
168 | 115 |
log.debug("Error in parsing json response. Given json is : "+json, e); |
116 |
e.printStackTrace(); |
|
169 | 117 |
return null; |
170 | 118 |
} |
171 | 119 |
|
172 |
log.debug("Original response.........: "+managersResponse.toString());
|
|
120 |
log.debug("Original response.........: "+managerUtilsList.size());
|
|
173 | 121 |
|
174 | 122 |
|
175 | 123 |
|
176 | 124 |
return managerUtilsList; |
177 | 125 |
} |
178 | 126 |
|
179 |
public Boolean isCommunityManager(String communityId, String userMail, String sessionId) {
|
|
180 |
List<ManagerUtils> managerUtils = this.getManagersByEmail(communityId, sessionId);
|
|
127 |
public Boolean isCommunityManager(String communityId, String userMail) { |
|
128 |
List<ManagerUtils> managerUtils = this.getManagersByEmail(communityId); |
|
181 | 129 |
if(managerUtils != null) { |
182 | 130 |
for(ManagerUtils manager : managerUtils) { |
183 | 131 |
if(manager.getEmail() != null && manager.getEmail().equals(userMail)) { |
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/emailSender/EmailScheduler.java | ||
---|---|---|
45 | 45 |
.getRequiredWebApplicationContext(servletContextEvent.getServletContext()) |
46 | 46 |
.getAutowireCapableBeanFactory() |
47 | 47 |
.autowireBean(this); |
48 |
|
|
48 |
logger.debug("Initializing EmailScheduler with beautySleep " + beautySleep + " and begin time " + targetHour + ":" + targetMinute + ":" + targetSecond + " and email sender " + emailSender); |
|
49 | 49 |
if(sendEmailNotifications) { |
50 | 50 |
logger.debug("Initializing EmailScheduler with beautySleep " + beautySleep + " and begin time " + targetHour + ":" + targetMinute + ":" + targetSecond + " and email sender " + emailSender); |
51 | 51 |
delay = getInitialDelaySeconds(Integer.parseInt(targetHour), Integer.parseInt(targetMinute), Integer.parseInt(targetSecond)); |
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/emailSender/EmailSender.java | ||
---|---|---|
52 | 52 |
private static String port; |
53 | 53 |
private static String from; |
54 | 54 |
private static String auth; |
55 |
private static String sslProtocols; |
|
55 | 56 |
private static String contactMail; |
56 | 57 |
private static String specialRecipients; |
57 | 58 |
private static String enabledCommunities; |
... | ... | |
201 | 202 |
} catch (SQLStoreException|Exception e) { |
202 | 203 |
logger.error("Could not fetch claims by date from "+dateFrom+" to "+dateTo, e); |
203 | 204 |
} |
204 |
|
|
205 |
logger.debug(claims.size() + "new claims found"); |
|
205 | 206 |
for (Claim claim: claims) { |
206 | 207 |
if (claim.getSourceType().equals("context")) { |
207 | 208 |
context = (Context)claim.getSource(); |
... | ... | |
210 | 211 |
} |
211 | 212 |
|
212 | 213 |
String openaireId = context.getOpenaireId().split("::")[0]; |
213 |
if (!managersOfCommunity.containsKey(openaireId) && enabledCommunitiesList != null && enabledCommunitiesList.contains(openaireId)) {
|
|
214 |
if (!managersOfCommunity.containsKey(openaireId) && (enabledCommunitiesList == null || enabledCommunitiesList.contains(openaireId))) {
|
|
214 | 215 |
|
215 | 216 |
/* |
216 | 217 |
// specialRecipients are used currently for testing purposes |
... | ... | |
227 | 228 |
List<String> managers = null; |
228 | 229 |
try { |
229 | 230 |
//CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(openaireId); |
230 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmailNoSession(openaireId);
|
|
231 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmail(openaireId); |
|
231 | 232 |
//managers = communityInfo.getManagers(); |
232 | 233 |
if(managerUtils != null) { |
233 |
Iterator<ManagerUtils> itr = managerUtils.iterator(); |
|
234 |
while (itr.hasNext()) { |
|
235 |
String manager = (String) itr.next().getEmail(); |
|
236 |
Notification notification = fetchNotificationHandler.fetchNotification(openaireId, manager); |
|
237 |
if (notification != null) { |
|
238 |
itr.remove(); |
|
239 |
} else { |
|
234 |
for (ManagerUtils manager:managerUtils) { |
|
235 |
String managerMail = manager.getEmail(); |
|
236 |
Notification notification = fetchNotificationHandler.fetchNotification(openaireId, managerMail); |
|
237 |
if (notification == null) { |
|
240 | 238 |
if(managers == null) { |
241 | 239 |
managers = new ArrayList<>(); |
242 | 240 |
} |
243 |
managers.add(manager); |
|
244 |
logger.debug("Sending email to community manager: "+ manager); |
|
241 |
managers.add(managerMail);
|
|
242 |
logger.debug("Sending email to community manager: "+ managerMail);
|
|
245 | 243 |
} |
246 | 244 |
} |
247 | 245 |
} |
... | ... | |
249 | 247 |
logger.debug("Community Managers: null"); |
250 | 248 |
} |
251 | 249 |
} catch (Exception e) { |
250 |
logger.error(e); |
|
252 | 251 |
e.printStackTrace(); |
253 | 252 |
} catch (SQLStoreException e) { |
254 | 253 |
e.printStackTrace(); |
254 |
logger.error(e); |
|
255 | 255 |
} |
256 | 256 |
|
257 | 257 |
logger.debug("Managers of community " + openaireId + ": "+managers); |
... | ... | |
262 | 262 |
!managersOfCommunity.get(openaireId).isEmpty()) { |
263 | 263 |
send(openaireId, context.getTitle().split(">")[0], "community", managersOfCommunity.get(openaireId)); |
264 | 264 |
} |
265 |
} else if(enabledCommunitiesList == null || !enabledCommunitiesList.contains(openaireId)) {
|
|
265 |
} else if(enabledCommunitiesList != null && !enabledCommunitiesList.contains(openaireId)) {
|
|
266 | 266 |
logger.debug("Community "+openaireId+" is not enabled"); |
267 | 267 |
} |
268 | 268 |
} |
... | ... | |
345 | 345 |
|
346 | 346 |
if(trueNotifications != null) { |
347 | 347 |
for(Notification notification : trueNotifications) { |
348 |
if (enabledCommunitiesList != null && enabledCommunitiesList.contains(notification.getOpenaireId())) {
|
|
348 |
if (enabledCommunitiesList == null || enabledCommunitiesList.contains(notification.getOpenaireId())) {
|
|
349 | 349 |
|
350 | 350 |
if(!allManagers.containsKey(notification.getOpenaireId())) { |
351 | 351 |
allManagers.put(notification.getOpenaireId(), new ArrayList()); |
352 | 352 |
|
353 | 353 |
// CommunityUtils communityInfo = this.communityUtils.getCommunityInfo(notification.getOpenaireId()); |
354 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmailNoSession(notification.getOpenaireId());
|
|
354 |
List<ManagerUtils> managerUtils = this.managerUtils.getManagersByEmail(notification.getOpenaireId()); |
|
355 | 355 |
|
356 | 356 |
// List<String> managers = null; |
357 | 357 |
if (managerUtils != null) { |
... | ... | |
451 | 451 |
properties.put("mail.smtp.port", port); |
452 | 452 |
properties.put("mail.smtp.auth", auth); //enable authentication |
453 | 453 |
properties.put("mail.smtp.starttls.enable", "true"); |
454 |
|
|
454 |
if(sslProtocols != null) { |
|
455 |
properties.put("mail.smtp.ssl.protocols", sslProtocols); |
|
456 |
} |
|
455 | 457 |
Session session = Session.getInstance(properties, |
456 | 458 |
new javax.mail.Authenticator() { |
457 | 459 |
protected PasswordAuthentication getPasswordAuthentication() { |
... | ... | |
595 | 597 |
public void setManagerUtils(ManagerUtils managerUtils) { |
596 | 598 |
this.managerUtils = managerUtils; |
597 | 599 |
} |
600 |
|
|
601 |
public static String getSslProtocols() { |
|
602 |
return sslProtocols; |
|
603 |
} |
|
604 |
|
|
605 |
public static void setSslProtocols(String sslProtocols) { |
|
606 |
EmailSender.sslProtocols = sslProtocols; |
|
607 |
} |
|
598 | 608 |
} |
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.registryAPIForManagerEmails = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email |
|
14 |
services.claims.closedRegistryAPIForManagerEmails = http://mpagasas.di.uoa.gr:8080/dnet-role-management/admin/community/ |
|
15 |
services.claims.sessionCookieName = openAIRESession |
|
16 |
services.claims.sessionCookieDomain = .openaire.eu |
|
13 |
services.claims.registryAPIForManagerEmails = http://mpagasas.di.uoa.gr:8080/dnet-role-management/admin/community/{community}?name=false |
|
17 | 14 |
services.claims.searchAPIUrl = http://beta.services.openaire.eu:8480/search/ |
18 | 15 |
#email properties |
19 | 16 |
## EMAIL SETTINGS |
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/springContext-claims.xml | ||
---|---|---|
109 | 109 |
<property name="port" value="${services.claims.mail.port}"/> |
110 | 110 |
<property name="auth" value="${services.claims.mail.auth}"/> |
111 | 111 |
<property name="from" value="${services.claims.mail.from}"/> |
112 |
<property name="sslProtocols" value="${services.claims.mail.sslProtocols}"/> |
|
112 | 113 |
<property name="contactMail" value="${services.claims.mail.contactMail}"/> |
113 | 114 |
<property name="specialRecipients" value="${services.claims.mail.specialRecipients}"/> |
114 | 115 |
<property name="defaultFrequencyInHours" ref="defaultFrequencyInHours"/> |
... | ... | |
124 | 125 |
</bean> |
125 | 126 |
<bean id="managerUtils" class="eu.dnetlib.data.claims.utils.ManagerUtils"> |
126 | 127 |
<property name="registryAPIForManagerEmails" value="${services.claims.registryAPIForManagerEmails}"/> |
127 |
<property name="closedRegistryAPIForManagerEmails" value="${services.claims.closedRegistryAPIForManagerEmails}"/> |
|
128 |
<property name="sessionCookieName" value="${services.claims.sessionCookieName}"/> |
|
129 |
<property name="sessionCookieDomain" value="${services.claims.sessionCookieDomain}"/> |
|
130 | 128 |
</bean> |
131 | 129 |
|
132 | 130 |
<bean id="sqlStore" class="eu.dnetlib.data.claims.sql.SqlStore" init-method="init" destroy-method="destroy"> |
Also available in: Unified diff
Clean up code use only the method to get managers without session cookie
add more checks if community is enabled for notifications or not