Skip to content
Snippets Groups Projects
Commit d28ed3a0 authored by Hugues.Cazeaux's avatar Hugues.Cazeaux
Browse files

feat(OAI-PMH): add parameter to define token life time

parent c1cc7159
No related branches found
No related tags found
1 merge request!318OAI-PMH fixes
......@@ -30,6 +30,7 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "solidify.oai-pmh")
public class OAIProperties {
private int pageSize = 100;
private int tokenLifeTimeMinutes = 5;
public int getPageSize() {
return this.pageSize;
......@@ -39,4 +40,12 @@ public class OAIProperties {
this.pageSize = pageSize;
}
public int getTokenLifeTimeMinutes() {
return this.tokenLifeTimeMinutes;
}
public void setTokenLifeTimeMinutes(int tokenLifeTimeMinutes) {
this.tokenLifeTimeMinutes = tokenLifeTimeMinutes;
}
}
......@@ -50,17 +50,17 @@ public class OAIToken {
public OAIToken() {
this.pageable = PageRequest.of(0, RestCollectionPage.DEFAULT_SIZE_PAGE);
this.setExpirationDate();
this.setExpirationDate(5);
}
public OAIToken(int oaiPmhPageSize) {
public OAIToken(int oaiPmhPageSize, int oaiPmhTokenLifeTime) {
this.pageable = PageRequest.of(0, oaiPmhPageSize);
this.setExpirationDate();
this.setExpirationDate(oaiPmhTokenLifeTime);
}
public OAIToken(int oaiPmhPageSize, Sort sort) {
public OAIToken(int oaiPmhPageSize, int oaiPmhTokenLifeTime, Sort sort) {
this.pageable = PageRequest.of(0, oaiPmhPageSize, sort);
this.setExpirationDate();
this.setExpirationDate(oaiPmhTokenLifeTime);
}
public BigInteger getCurrentItems() {
......@@ -79,9 +79,9 @@ public class OAIToken {
return this.pageable;
}
public ResumptionTokenType getToken(long totalItems, long previousItems) {
public ResumptionTokenType getToken(long totalItems, long previousItems, int oaiPmhTokenLifeTime) {
final ResumptionTokenType resumptionToken = new ResumptionTokenType();
this.setExpirationDate();
this.setExpirationDate(oaiPmhTokenLifeTime);
this.setTotalItems(BigInteger.valueOf(totalItems));
this.setCurrentItems(BigInteger.valueOf(previousItems));
resumptionToken.setCompleteListSize(this.getTotalItems());
......@@ -155,8 +155,8 @@ public class OAIToken {
return params;
}
private void setExpirationDate() {
this.expirationDate = OffsetDateTime.now(ZoneOffset.UTC).plusMinutes(5);
private void setExpirationDate(int lifeTimeMinutes) {
this.expirationDate = OffsetDateTime.now(ZoneOffset.UTC).plusMinutes(lifeTimeMinutes);
}
private void setParameters(String parameters) {
......
......@@ -96,6 +96,7 @@ public class OAIService {
private List<Class<?>> xmlClasses = new ArrayList<>(Arrays.asList(OAIPMHtype.class, OaiDcType.class, OaiIdentifierType.class, Html.class));
private final int oaiPmhPageSize;
private final int oaiPmhTokenLifeTime;
private final ObjectFactory oaiDcFactory = new ObjectFactory();
// OAI Objects
......@@ -118,6 +119,7 @@ public class OAIService {
OAIMetadataService metadataService) {
this.oaiRepositoryInfo = oaiRepositoryInfo;
this.oaiPmhPageSize = oaiProperties.getPageSize();
this.oaiPmhTokenLifeTime = oaiProperties.getTokenLifeTimeMinutes();
this.oaiMetadataPrefixService = oaiMetadataPrefixService;
this.oaiSetService = oaiSetService;
this.searchService = searchService;
......@@ -249,7 +251,8 @@ public class OAIService {
idList.getHeader().add(this.getIdentifier(oaiRecord));
}
if (collection.getPage().hasNext()) {
idList.setResumptionToken(oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems()));
idList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime));
}
return idList;
}
......@@ -299,7 +302,8 @@ public class OAIService {
}
if (collection.getPage().hasNext()) {
recList.setResumptionToken(oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems()));
recList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime));
}
return recList;
}
......@@ -309,7 +313,7 @@ public class OAIService {
/*
* Pagination may be given by an URL token
*/
final OAIToken oaiToken = new OAIToken(this.oaiPmhPageSize, Sort.by("name"));
final OAIToken oaiToken = new OAIToken(this.oaiPmhPageSize, this.oaiPmhTokenLifeTime, Sort.by("name"));
if (!StringTool.isNullOrEmpty(token)) {
oaiToken.setToken(token);
}
......@@ -383,7 +387,7 @@ public class OAIService {
}
private OAIToken checkParameters(String metadataPrefix, String from, String until, String set, String token) {
final OAIToken oaiToken = new OAIToken(this.oaiPmhPageSize);
final OAIToken oaiToken = new OAIToken(this.oaiPmhPageSize, this.oaiPmhTokenLifeTime);
// Token parameter
if (!StringTool.isNullOrEmpty(token)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment