-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coding done, working on some unit tests (#7152)
* Coding done, working on some unit tests * More unit tests * Unit tests done
- Loading branch information
1 parent
cccb6a1
commit ce68e23
Showing
5 changed files
with
219 additions
and
31 deletions.
There are no files selected for viewing
11 changes: 6 additions & 5 deletions
11
orcid-core/src/main/resources/org/orcid/core/template/papi_rate_limit_email.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
|
||
@Component | ||
public class ApiRateLimitFilter extends OncePerRequestFilter { | ||
private static Logger LOG = LoggerFactory.getLogger(ApiRateLimitFilter.class); | ||
private static final Logger LOG = LoggerFactory.getLogger(ApiRateLimitFilter.class); | ||
|
||
@Autowired | ||
private PublicApiDailyRateLimitDao papiRateLimitingDao; | ||
|
@@ -61,9 +61,6 @@ public class ApiRateLimitFilter extends OncePerRequestFilter { | |
@Autowired | ||
private MailGunManager mailGunManager; | ||
|
||
@Autowired | ||
private ProfileDao profileDao; | ||
|
||
@Autowired | ||
private OrcidUrlManager orcidUrlManager; | ||
|
||
|
@@ -110,11 +107,14 @@ public class ApiRateLimitFilter extends OncePerRequestFilter { | |
+ "You can increase your daily quota by registering for and using Public API client credentials " | ||
+ "(https://info.orcid.org/documentation/integration-guide/registering-a-public-api-client/ )"; | ||
|
||
private static final String SUBJECT = "[ORCID] You have exceeded the daily Public API Usage Limit - "; | ||
private static final String SUBJECT = "[ORCID-API] WARNING! You have exceeded the daily Public API Usage Limit - "; | ||
|
||
@Value("${org.orcid.papi.rate.limit.fromEmail:notify@notify.orcid.org}") | ||
@Value("${org.orcid.papi.rate.limit.fromEmail:apiusage@orcid.org}") | ||
private String FROM_ADDRESS; | ||
|
||
@Value("${org.orcid.papi.rate.limit.ccAddress:[email protected]}") | ||
private String CC_ADDRESS; | ||
|
||
@Override | ||
public void afterPropertiesSet() throws ServletException { | ||
super.afterPropertiesSet(); | ||
|
@@ -123,7 +123,7 @@ public void afterPropertiesSet() throws ServletException { | |
} | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) | ||
public void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
LOG.trace("ApiRateLimitFilter starts, rate limit is : " + enableRateLimiting); | ||
if (enableRateLimiting) { | ||
|
@@ -197,7 +197,6 @@ private void rateLimitAnonymousRequest(String ipAddress, LocalDate today, HttpSe | |
|
||
} | ||
return; | ||
|
||
} | ||
|
||
private void rateLimitClientRequest(String clientId, LocalDate today) { | ||
|
@@ -240,30 +239,30 @@ private Map<String, Object> createTemplateParams(String clientId, String clientN | |
|
||
private void sendEmail(String clientId, LocalDate requestDate) { | ||
ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(clientId); | ||
ProfileEntity profile = profileDao.find(clientDetailsEntity.getGroupProfileId()); | ||
String emailName = recordNameManager.deriveEmailFriendlyName(profile.getId()); | ||
Map<String, Object> templateParams = this.createTemplateParams(clientId, clientDetailsEntity.getClientName(), emailName, profile.getId()); | ||
String memberId = clientDetailsEntity.getGroupProfileId(); | ||
String emailName = recordNameManager.deriveEmailFriendlyName(memberId); | ||
Map<String, Object> templateParams = this.createTemplateParams(clientId, clientDetailsEntity.getClientName(), emailName, memberId); | ||
// Generate body from template | ||
String body = templateManager.processTemplate("papi_rate_limit_email.ftl", templateParams); | ||
// Generate html from template | ||
String html = templateManager.processTemplate("papi_rate_limit_email_html.ftl", templateParams); | ||
String email = emailManager.findPrimaryEmail(profile.getId()).getEmail(); | ||
String email = emailManager.findPrimaryEmail(memberId).getEmail(); | ||
LOG.info("from address={}", FROM_ADDRESS); | ||
LOG.info("text email={}", body); | ||
LOG.info("html email={}", html); | ||
if (enablePanoplyPapiExceededRateInProduction) { | ||
PanoplyPapiDailyRateExceededItem item = new PanoplyPapiDailyRateExceededItem(); | ||
item.setClientId(clientId); | ||
item.setOrcid(profile.getId()); | ||
item.setOrcid(memberId); | ||
item.setEmail(email); | ||
item.setRequestDate(requestDate); | ||
setPapiRateExceededItemInPanoply(item); | ||
} | ||
|
||
// Send the email | ||
boolean mailSent = mailGunManager.sendEmail(FROM_ADDRESS, email, SUBJECT, body, html); | ||
boolean mailSent = mailGunManager.sendEmailWithCC(FROM_ADDRESS, email, CC_ADDRESS, SUBJECT, body, html); | ||
if (!mailSent) { | ||
LOG.error("Failed to send email for papi limits, orcid=" + profile.getId() + " email: " + email); | ||
LOG.error("Failed to send email for papi limits, orcid=" + memberId + " email: " + email); | ||
} | ||
} | ||
|
||
|
@@ -281,7 +280,6 @@ private void setPapiRateExceededItemInPanoply(PanoplyPapiDailyRateExceededItem i | |
if (!result) { | ||
LOG.error("Async call to panoply for : " + item.toString() + " Stored: " + result); | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
@@ -301,11 +299,10 @@ private String getClientIpAddress(HttpServletRequest request) { | |
} | ||
|
||
private boolean isWhiteListed(String ipAddress) { | ||
return (papiIpWhiteList != null)?papiIpWhiteList.contains(ipAddress): false; | ||
return (papiIpWhiteList != null) ? papiIpWhiteList.contains(ipAddress) : false; | ||
} | ||
|
||
private boolean isClientIdWhiteListed(String clientId) { | ||
return (papiClientIdWhiteList != null)?papiClientIdWhiteList.contains(clientId):false; | ||
return (papiClientIdWhiteList != null) ? papiClientIdWhiteList.contains(clientId) :false; | ||
} | ||
|
||
} |
Oops, something went wrong.