use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.
the class RecordCorrectionsManagerReadOnlyImpl method getInvalidRecordDataChangesAscending.
@Override
@Cacheable(value = "invalid-record-data-change-page-asc", key = "(#lastElement == null ? 'none' : #lastElement.toString()).concat('-').concat(#pageSize.toString())")
public RecordCorrectionsPage getInvalidRecordDataChangesAscending(Long lastElement, Long pageSize) {
List<InvalidRecordDataChangeEntity> entities = dao.getByDateCreated(lastElement, pageSize, ASCENDING);
if (entities == null || entities.isEmpty()) {
throw new IllegalArgumentException("Unable to find a page with the following params: lastElement=" + lastElement + " pageSize: " + pageSize + " ascending order");
}
List<RecordCorrection> elements = adapter.toInvalidRecordDataChanges(entities);
Long first = null;
Long last = null;
for (RecordCorrection element : elements) {
if (first == null || element.getSequence() < first) {
first = element.getSequence();
}
if (last == null || element.getSequence() > last) {
last = element.getSequence();
}
}
Boolean haveNext = dao.haveNext(last, ASCENDING);
Boolean havePrevious = dao.havePrevious(first, ASCENDING);
RecordCorrectionsPage page = new RecordCorrectionsPage();
page.setFirstElementId(first);
page.setLastElementId(last);
page.setHaveNext(haveNext);
page.setHavePrevious(havePrevious);
page.setRecordCorrections(elements);
return page;
}
use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.
the class RecordCorrectionsControllerTest method nextOnFirstPageTest.
@Test
public void nextOnFirstPageTest() {
RecordCorrectionsPage page1 = controller.getNextDescending(Optional.empty());
assertNotNull(page1);
assertFalse(page1.getHavePrevious());
assertTrue(page1.getHaveNext());
assertEquals(Long.valueOf(1015), page1.getFirstElementId());
assertEquals(Long.valueOf(1006), page1.getLastElementId());
assertNotNull(page1.getRecordCorrections());
assertEquals(10, page1.getRecordCorrections().size());
RecordCorrectionsPage page2 = controller.getNextDescending(Optional.of(page1.getLastElementId()));
assertNotNull(page2);
assertTrue(page2.getHavePrevious());
assertFalse(page2.getHaveNext());
assertEquals(Long.valueOf(1005), page2.getFirstElementId());
assertEquals(Long.valueOf(1000), page2.getLastElementId());
assertNotNull(page2.getRecordCorrections());
assertEquals(6, page2.getRecordCorrections().size());
}
use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.
the class RecordCorrectionsControllerTest method previousOnLastPageTest.
@Test
public void previousOnLastPageTest() {
RecordCorrectionsPage page1 = controller.getPreviousDescending(Optional.empty());
assertNotNull(page1);
assertTrue(page1.getHavePrevious());
assertFalse(page1.getHaveNext());
assertEquals(Long.valueOf(1009), page1.getFirstElementId());
assertEquals(Long.valueOf(1000), page1.getLastElementId());
assertNotNull(page1.getRecordCorrections());
assertEquals(10, page1.getRecordCorrections().size());
RecordCorrectionsPage page2 = controller.getPreviousDescending(Optional.of(page1.getFirstElementId()));
assertNotNull(page2);
assertFalse(page2.getHavePrevious());
assertTrue(page2.getHaveNext());
assertEquals(Long.valueOf(1015), page2.getFirstElementId());
assertEquals(Long.valueOf(1010), page2.getLastElementId());
assertNotNull(page2.getRecordCorrections());
assertEquals(6, page2.getRecordCorrections().size());
}
use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.
the class RecordCorrectionsManagerReadOnlyTest method getElementsDescendingTest.
@Test
public void getElementsDescendingTest() {
// Page 1
RecordCorrectionsPage page1 = manager.getInvalidRecordDataChangesDescending(10L, 4L);
assertNotNull(page1);
assertEquals(Long.valueOf(10), page1.getFirstElementId());
assertEquals(Long.valueOf(7), page1.getLastElementId());
assertTrue(page1.getHaveNext());
assertFalse(page1.getHavePrevious());
assertNotNull(page1.getRecordCorrections());
assertEquals(4, page1.getRecordCorrections().size());
Long currentId = null;
for (RecordCorrection element : page1.getRecordCorrections()) {
if (currentId == null) {
assertEquals(page1.getFirstElementId(), element.getSequence());
currentId = element.getSequence();
} else {
assertTrue((currentId - 1) == element.getSequence());
currentId = element.getSequence();
}
}
assertEquals(page1.getLastElementId(), currentId);
// Page 2
RecordCorrectionsPage page2 = manager.getInvalidRecordDataChangesDescending(page1.getLastElementId() - 1, 4L);
assertNotNull(page2);
assertEquals(Long.valueOf(6), page2.getFirstElementId());
assertEquals(Long.valueOf(3), page2.getLastElementId());
assertTrue(page2.getHaveNext());
assertTrue(page2.getHavePrevious());
assertNotNull(page2.getRecordCorrections());
assertEquals(4, page2.getRecordCorrections().size());
currentId = null;
for (RecordCorrection element : page2.getRecordCorrections()) {
if (currentId == null) {
assertEquals(page2.getFirstElementId(), element.getSequence());
currentId = element.getSequence();
} else {
assertTrue((currentId - 1) == element.getSequence());
currentId = element.getSequence();
}
}
assertEquals(page2.getLastElementId(), currentId);
//Page 3
RecordCorrectionsPage page3 = manager.getInvalidRecordDataChangesDescending(page2.getLastElementId() - 1, 4L);
assertNotNull(page3);
assertEquals(Long.valueOf(2), page3.getFirstElementId());
assertEquals(Long.valueOf(1), page3.getLastElementId());
assertFalse(page3.getHaveNext());
assertTrue(page3.getHavePrevious());
assertEquals(2, page3.getRecordCorrections().size());
currentId = null;
for (RecordCorrection element : page3.getRecordCorrections()) {
if (currentId == null) {
assertEquals(page3.getFirstElementId(), element.getSequence());
currentId = element.getSequence();
} else {
assertTrue((currentId - 1) == element.getSequence());
currentId = element.getSequence();
}
}
assertEquals(page3.getLastElementId(), currentId);
}
Aggregations