Skip to content

Commit

Permalink
Send summary to cache (#7027)
Browse files Browse the repository at this point in the history
* Deactivated records should get 409 on GET requests

* Send the summary to the cache

* Fix unit tests

* On the UI endpoint return json by default

* Working on API object

* Working on model object

* Working on model object

* Working on unit tests

* Unit tests done

* Adding more unit tests

* Ready to test

* Add type to professional activities

* Ready to go

* Fix unit tests
  • Loading branch information
amontenegro authored Apr 28, 2024
1 parent 1efc38f commit 1c5f82a
Show file tree
Hide file tree
Showing 47 changed files with 1,627 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.orcid.core.manager.v3.read_only.ResearchResourceManagerReadOnly;
import org.orcid.core.manager.v3.read_only.ResearcherUrlManagerReadOnly;
import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly;
import org.orcid.core.model.RecordSummary;
import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.core.utils.v3.ContributorUtils;
import org.orcid.core.utils.v3.SourceUtils;
Expand Down Expand Up @@ -127,7 +128,6 @@
import org.orcid.jaxb.model.v3.release.record.summary.Works;
import org.orcid.jaxb.model.v3.release.search.Search;
import org.orcid.jaxb.model.v3.release.search.expanded.ExpandedSearch;
import org.orcid.pojo.summary.RecordSummary;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package org.orcid.persistence.aop;
package org.orcid.core.aop;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.orcid.core.utils.cache.redis.RedisClient;
import org.orcid.persistence.dao.ProfileLastModifiedDao;
import org.orcid.persistence.jpa.entities.IndexingStatus;
import org.orcid.persistence.jpa.entities.OrcidAware;
import org.orcid.persistence.util.OrcidStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.PriorityOrdered;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
Expand Down Expand Up @@ -40,6 +44,12 @@ public class ProfileLastModifiedAspect implements PriorityOrdered {

private static final String UPDATE_PROFILE_LAST_MODIFIED_AND_INDEXING_STATUS = "@annotation(org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus)";

@Resource
private RedisClient redisClient;

@Value("${org.orcid.core.utils.cache.redis.summary.enabled:false}")
private boolean isSummaryCacheEnabled;

public boolean isEnabled() {
return enabled;
}
Expand Down Expand Up @@ -125,7 +135,10 @@ public void updateLastModifiedDateAndIndexingStatus(String orcid) {

ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null)
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);

// Clear redis caches
evictCaches(orcid);
}

/** Updates the last modified date and clears the request-scope last modified cache.
Expand All @@ -144,7 +157,10 @@ public void updateLastModifiedDate(String orcid) {

ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null)
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);

// Clear redis caches
evictCaches(orcid);
}

/** Fetches the last modified from the request-scope last modified cache
Expand All @@ -169,4 +185,9 @@ public Date retrieveLastModifiedDate(String orcid) {
private String sraKey(String orcid) {
return REQUEST_PROFILE_LAST_MODIFIED + '_' + name + '_' + orcid;
}

public void evictCaches(String orcid) {
// Evict the summary cache
redisClient.remove(orcid + "-summary");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.orcid.core.common.manager;

import org.orcid.pojo.summary.RecordSummary;
import org.orcid.core.model.RecordSummary;
import org.orcid.pojo.summary.RecordSummaryPojo;

public interface SummaryManager {
RecordSummary getRecordSummary(String orcid);

RecordSummaryPojo getRecordSummaryPojo(String orcid);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private String getCacheKey(String sourceId) {
}

private String getClientSourceName(String clientId) {
LOGGER.debug("Fetching client name from DB: " + clientId);
if (clientDetailsDao.existsAndIsNotPublicClient(clientId)) {
ClientDetailsEntity clientDetails = clientDetailsDao.find(clientId);
return clientDetails != null ? clientDetails.getClientName() : null;
Expand All @@ -110,6 +111,7 @@ private String getProfileSourceNameFromRequest(String orcid) {
}

private String getProfileSourceNameFromDb(String orcid) {
LOGGER.debug("Fetching user name from DB: " + orcid);
try {
if (!recordNameDao.exists(orcid)) {
throw new IllegalArgumentException("Unable to find source name for: " + orcid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Date;

import org.orcid.persistence.aop.ProfileLastModifiedAspect;
import org.orcid.core.aop.ProfileLastModifiedAspect;

public interface ManagerReadOnlyBase {
void setProfileLastModifiedAspect(ProfileLastModifiedAspect profileLastModifiedAspect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.Date;

import org.orcid.core.aop.ProfileLastModifiedAspect;
import org.orcid.core.manager.read_only.ManagerReadOnlyBase;
import org.orcid.persistence.aop.ProfileLastModifiedAspect;

public class ManagerReadOnlyBaseImpl implements ManagerReadOnlyBase {
protected ProfileLastModifiedAspect profileLastModifiedAspect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Date;

import org.orcid.persistence.aop.ProfileLastModifiedAspect;
import org.orcid.core.aop.ProfileLastModifiedAspect;

public interface ManagerReadOnlyBase {
void setProfileLastModifiedAspect(ProfileLastModifiedAspect profileLastModifiedAspect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.Date;

import org.orcid.core.aop.ProfileLastModifiedAspect;
import org.orcid.core.manager.v3.read_only.ManagerReadOnlyBase;
import org.orcid.persistence.aop.ProfileLastModifiedAspect;

public class ManagerReadOnlyBaseImpl implements ManagerReadOnlyBase {
protected ProfileLastModifiedAspect profileLastModifiedAspect;
Expand Down
106 changes: 106 additions & 0 deletions orcid-core/src/main/java/org/orcid/core/model/Employment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.orcid.core.model;

import java.io.Serializable;
import java.util.Objects;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.orcid.jaxb.model.v3.release.common.FuzzyDate;
import org.orcid.jaxb.model.v3.release.record.AffiliationType;

import io.swagger.v3.oas.annotations.media.Schema;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "putCode", "type", "organizationName", "role", "url", "startDate", "endDate", "validated" })
@XmlRootElement(name = "employment", namespace = "http://www.orcid.org/ns/summary")
@Schema(description = "Employment")
public class Employment implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@XmlElement(name = "put-code", namespace = "http://www.orcid.org/ns/summary")
protected Long putCode;
@XmlElement(name = "start-date", namespace = "http://www.orcid.org/ns/common")
protected FuzzyDate startDate;
@XmlElement(name = "end-date", namespace = "http://www.orcid.org/ns/common")
protected FuzzyDate endDate;
@XmlElement(name = "type", namespace = "http://www.orcid.org/ns/summary")
protected final String type = AffiliationType.EMPLOYMENT.value();
@XmlElement(name = "organization-name", namespace = "http://www.orcid.org/ns/summary")
protected String organizationName;
@XmlElement(name = "role", namespace = "http://www.orcid.org/ns/summary")
protected String role;
@XmlElement(name = "url", namespace = "http://www.orcid.org/ns/summary")
protected String url;
@XmlElement(name = "validated", namespace = "http://www.orcid.org/ns/summary")
protected boolean validated;
public Long getPutCode() {
return putCode;
}
public void setPutCode(Long putCode) {
this.putCode = putCode;
}
public FuzzyDate getStartDate() {
return startDate;
}
public void setStartDate(FuzzyDate startDate) {
this.startDate = startDate;
}
public FuzzyDate getEndDate() {
return endDate;
}
public void setEndDate(FuzzyDate endDate) {
this.endDate = endDate;
}
public String getOrganizationName() {
return organizationName;
}
public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public boolean isValidated() {
return validated;
}
public void setValidated(boolean validated) {
this.validated = validated;
}
public String getType() {
return type;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public int hashCode() {
return Objects.hash(endDate, organizationName, putCode, role, startDate, url, validated);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employment other = (Employment) obj;
return Objects.equals(endDate, other.endDate) && Objects.equals(organizationName, other.organizationName) && Objects.equals(putCode, other.putCode)
&& Objects.equals(role, other.role) && Objects.equals(startDate, other.startDate) && Objects.equals(url, other.url) && validated == other.validated;
}
}
61 changes: 61 additions & 0 deletions orcid-core/src/main/java/org/orcid/core/model/Employments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.orcid.core.model;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import io.swagger.v3.oas.annotations.media.Schema;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "count", "employments" })
@XmlRootElement(name = "employments", namespace = "http://www.orcid.org/ns/summary")
@Schema(description = "Employments list")
public class Employments implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@XmlElement(name = "count", namespace = "http://www.orcid.org/ns/summary")
private Integer count;
@XmlElement(name = "employment", namespace = "http://www.orcid.org/ns/summary")
private List<Employment> employments;

public Integer getCount() {
return count;
}

public void setCount(Integer count) {
this.count = count;
}

public List<Employment> getEmployments() {
return employments;
}

public void setEmployments(List<Employment> employments) {
this.employments = employments;
}

@Override
public int hashCode() {
return Objects.hash(count, employments);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employments other = (Employments) obj;
return Objects.equals(count, other.count) && Objects.equals(employments, other.employments);
}
}
Loading

0 comments on commit 1c5f82a

Please sign in to comment.