Skip to content
Snippets Groups Projects
Commit 0ee88503 authored by Hugues.Cazeaux's avatar Hugues.Cazeaux Committed by Nicolas.Rod
Browse files

feat(OAI-PMH): resumptionToken must be present on last page with an empty...

feat(OAI-PMH): resumptionToken must be present on last page with an empty value when lists are paginated
parent 2f04e924
No related branches found
No related tags found
1 merge request!320feat(OAI-PMH): support the case of last token
......@@ -9,12 +9,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
......@@ -79,15 +79,20 @@ public class OAIToken {
return this.pageable;
}
public ResumptionTokenType getToken(long totalItems, long previousItems, int oaiPmhTokenLifeTime) {
public ResumptionTokenType getToken(long totalItems, long previousItems, int oaiPmhTokenLifeTime, boolean lastPage) {
final ResumptionTokenType resumptionToken = new ResumptionTokenType();
this.setExpirationDate(oaiPmhTokenLifeTime);
// set total items
this.setTotalItems(BigInteger.valueOf(totalItems));
this.setCurrentItems(BigInteger.valueOf(previousItems));
resumptionToken.setCompleteListSize(this.getTotalItems());
// set cursor = items already read
this.setCurrentItems(BigInteger.valueOf(previousItems));
resumptionToken.setCursor(this.getCurrentItems());
resumptionToken.setExpirationDate(this.getExpirationDate());
resumptionToken.setValue(this.encodeResumptionToken());
if (!lastPage) {
// If token is not on the last page, fill its value
this.setExpirationDate(oaiPmhTokenLifeTime);
resumptionToken.setExpirationDate(this.getExpirationDate());
resumptionToken.setValue(this.encodeResumptionToken());
}
return resumptionToken;
}
......
......@@ -251,7 +251,11 @@ public class OAIService {
}
if (collection.getPage().hasNext()) {
idList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime));
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime, false));
} else if (token != null) {
// If results are paginated, a resumptionToken must be present on the last page, but with an empty value
idList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime, true));
}
return idList;
}
......@@ -302,8 +306,13 @@ public class OAIService {
if (collection.getPage().hasNext()) {
recList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime));
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime, false));
} else if (token != null) {
// If results are paginated, a resumptionToken must be present on the last page, but with an empty value
recList.setResumptionToken(
oaiToken.getToken(collection.getPage().getTotalItems(), collection.getPage().getPreviousItems(), this.oaiPmhTokenLifeTime, true));
}
return recList;
}
......
......@@ -31,11 +31,17 @@ import ch.unige.solidify.SolidifyConstants;
public class OffsetDateTimeAdapter {
public static OffsetDateTime parseDateTime(String value) {
return OffsetDateTime.parse(value);
if (value != null) {
return OffsetDateTime.parse(value);
}
return null;
}
public static String printDateTime(OffsetDateTime value) {
return value.format(DateTimeFormatter.ISO_INSTANT);
if (value != null) {
return value.format(DateTimeFormatter.ISO_INSTANT);
}
return null;
}
/**
......
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