Skip to content

Commit

Permalink
Coding done, working on some unit tests (#7152)
Browse files Browse the repository at this point in the history
* Coding done, working on some unit tests

* More unit tests

* Unit tests done
  • Loading branch information
amontenegro authored Dec 16, 2024
1 parent cccb6a1 commit ce68e23
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<#import "email_macros.ftl" as emailMacros />
Dear ${emailName},

This is an important message to let you know that you have exceeded our daily Public API usage limit with your integration:
This is an important message to let you know that you have exceeded your daily Public API usage limit with your integration (https://info.orcid.org/ufaqs/what-are-the-api-limits/):

Client Name: ${clientName}
Client ID: ${clientId}

Please remember that the ORCID Public API is free for non-commercial use by individuals as stated in the Public APIs Terms of Service (https://info.orcid.org/public-client-terms-of-service/). By “non-commercial” we mean that you may not charge any re-use fees for the Public API, and you may not make use of the Public API in connection with any revenue-generating product or service
Please remember that the ORCID Public API is free for non-commercial use by individuals as stated in the Public APIs Terms of Service (https://info.orcid.org/public-client-terms-of-service). By “non-commercial” we mean that you may not charge any re-use fees for the Public API, and you may not make use of the Public API in connection with any revenue-generating product or service.

If you need access to an ORCID API for commercial use, need a higher usage quota, organizational administration of your API credentials, or the ability to write data to or access Trusted Party data in ORCID records, our Member API (https://info.orcid.org/documentation/features/member-api/) is available to ORCID member organizations.
Based on your API usage, we highly recommend you consider becoming an ORCID member for access to our Member API (https://info.orcid.org/documentation/features/member-api/). Not only will it allow you to access a higher Rate Limits and an unrestricted Usage Quota, but you will be able to access Trusted Party data in ORCID records and contribute data to ORCID records from your institutional systems.

To minimize any disruption to your ORCID integration in the future, we would recommend that you reach out to our Engagement Team by replying to this email to discuss our ORCID membership options.
To minimize any disruption to your ORCID integration in the future, we would recommend that you reach out to our Engagement Team by replying to this email to discuss our ORCID membership options.

Warm Regards,

Warm Regards,
ORCID Support Team
https://support.orcid.org

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<img src="https://orcid.org/sites/all/themes/orcid/img/orcid-logo.png" alt="ORCID.org"/>
<hr />
<span style="font-family: arial, helvetica, sans-serif; font-size: 15px; color: #494A4C; font-weight: bold;">Dear ${emailName},</span>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">This is an important message to let you know that you have exceeded our daily Public API usage limit with your integration:</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">This is an important message to let you know that you have exceeded your <a href="https://info.orcid.org/ufaqs/what-are-the-api-limits/" target="_blank">daily Public API usage limit</a> with your integration:</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">Client Name: ${clientName}</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">Client ID: ${clientId}</p>
<br/>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">Please remember that the ORCID Public API is free for non-commercial use by individuals as stated in the Public APIs Terms of Service (https://info.orcid.org/public-client-terms-of-service/). By “non-commercial” we mean that you may not charge any re-use fees for the Public API, and you may not make use of the Public API in connection with any revenue-generating product or service.</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">If you need access to an ORCID API for commercial use, need a higher usage quota, organizational administration of your API credentials, or the ability to write data to or access Trusted Party data in ORCID records, our Member API (https://info.orcid.org/documentation/features/member-api/) is available to ORCID member organizations.</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">Please remember that the ORCID Public API is free for non-commercial use by individuals as stated in the <a href="https://info.orcid.org/public-client-terms-of-service/" target="_blank">Public APIs Terms of Service</a>. By “non-commercial” we mean that you may not charge any re-use fees for the Public API, and you may not make use of the Public API in connection with any revenue-generating product or service.</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">Based on your API usage, we highly recommend you consider becoming an ORCID member for access to our <a href="https://info.orcid.org/documentation/features/member-api/" target="_blank">Member API</a>. Not only will it allow you to access a higher Rate Limits and an unrestricted Usage Quota, but you will be able to access Trusted Party data in ORCID records and contribute data to ORCID records from your institutional systems.</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">To minimize any disruption to your ORCID integration in the future, we would recommend that you reach out to our Engagement Team by replying to this email to discuss our ORCID membership options.
<br/>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C; white-space: pre;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,9 +61,6 @@ public class ApiRateLimitFilter extends OncePerRequestFilter {
@Autowired
private MailGunManager mailGunManager;

@Autowired
private ProfileDao profileDao;

@Autowired
private OrcidUrlManager orcidUrlManager;

Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -197,7 +197,6 @@ private void rateLimitAnonymousRequest(String ipAddress, LocalDate today, HttpSe

}
return;

}

private void rateLimitClientRequest(String clientId, LocalDate today) {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -281,7 +280,6 @@ private void setPapiRateExceededItemInPanoply(PanoplyPapiDailyRateExceededItem i
if (!result) {
LOG.error("Async call to panoply for : " + item.toString() + " Stored: " + result);
}

});
}

Expand All @@ -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;
}

}
Loading

0 comments on commit ce68e23

Please sign in to comment.