Search in sources :

Example 1 with RecordCorrectionsPage

use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.

the class RecordCorrectionsManagerReadOnlyImpl method getInvalidRecordDataChangesDescending.

@Override
@Cacheable(value = "invalid-record-data-change-page-desc", key = "(#lastElement == null ? 'none' : #lastElement.toString()).concat('-').concat(#pageSize.toString())")
public RecordCorrectionsPage getInvalidRecordDataChangesDescending(Long lastElement, Long pageSize) {
    List<InvalidRecordDataChangeEntity> entities = dao.getByDateCreated(lastElement, pageSize, DESCENDING);
    if (entities == null || entities.isEmpty()) {
        throw new IllegalArgumentException("Unable to find a page with the following params: lastElement=" + lastElement + " pageSize: " + pageSize + " descending 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, DESCENDING);
    Boolean havePrevious = dao.havePrevious(first, DESCENDING);
    RecordCorrectionsPage page = new RecordCorrectionsPage();
    page.setFirstElementId(first);
    page.setLastElementId(last);
    page.setHaveNext(haveNext);
    page.setHavePrevious(havePrevious);
    page.setRecordCorrections(elements);
    return page;
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) RecordCorrection(org.orcid.model.record_correction.RecordCorrection) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with RecordCorrectionsPage

use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.

the class RecordCorrectionsController method getPreviousDescending.

@RequestMapping(value = { "/record-corrections/previous", "/record-corrections/previous/{id}" }, method = RequestMethod.GET)
@ResponseBody
public RecordCorrectionsPage getPreviousDescending(@PathVariable Optional<Long> id) {
    try {
        RecordCorrectionsPage page = manager.getInvalidRecordDataChangesAscending(id.orElse(null), PAGE_SIZE);
        // Reverse the elements
        Collections.reverse(page.getRecordCorrections());
        // Reverse the next and previous elements
        boolean newNext = page.getHavePrevious();
        boolean newPrevious = page.getHaveNext();
        page.setHaveNext(newNext);
        page.setHavePrevious(newPrevious);
        Long newFirstElement = page.getLastElementId();
        Long newLastElement = page.getFirstElementId();
        page.setFirstElementId(newFirstElement);
        page.setLastElementId(newLastElement);
        return page;
    } catch (IllegalArgumentException e) {
    }
    return new RecordCorrectionsPage();
}
Also used : RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with RecordCorrectionsPage

use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.

the class RecordCorrectionsControllerTest method previousOnFirstPageTest.

@Test
public void previousOnFirstPageTest() {
    RecordCorrectionsPage page = controller.getPreviousDescending(Optional.of(1015L));
    assertNotNull(page);
    assertNull(page.getFirstElementId());
    assertNull(page.getLastElementId());
    assertFalse(page.getHaveNext());
    assertFalse(page.getHavePrevious());
    assertNull(page.getLastElementId());
}
Also used : RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 4 with RecordCorrectionsPage

use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.

the class RecordCorrectionsControllerTest method nextOnLastPageTest.

@Test
public void nextOnLastPageTest() {
    RecordCorrectionsPage page = controller.getNextDescending(Optional.of(1000L));
    assertNotNull(page);
    assertNull(page.getFirstElementId());
    assertNull(page.getLastElementId());
    assertFalse(page.getHaveNext());
    assertFalse(page.getHavePrevious());
    assertNull(page.getLastElementId());
}
Also used : RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 5 with RecordCorrectionsPage

use of org.orcid.model.record_correction.RecordCorrectionsPage in project ORCID-Source by ORCID.

the class RecordCorrectionsManagerReadOnlyTest method getElementsAscendingTest.

@Test
public void getElementsAscendingTest() {
    // Page 1
    RecordCorrectionsPage page1 = manager.getInvalidRecordDataChangesAscending(1L, 4L);
    assertNotNull(page1);
    assertEquals(Long.valueOf(1), page1.getFirstElementId());
    assertEquals(Long.valueOf(4), 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.getInvalidRecordDataChangesAscending(page1.getLastElementId() + 1, 4L);
    assertNotNull(page2);
    assertEquals(Long.valueOf(5), page2.getFirstElementId());
    assertEquals(Long.valueOf(8), 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.getInvalidRecordDataChangesAscending(page2.getLastElementId() + 1, 4L);
    assertNotNull(page3);
    assertEquals(Long.valueOf(9), page3.getFirstElementId());
    assertEquals(Long.valueOf(10), page3.getLastElementId());
    assertFalse(page3.getHaveNext());
    assertTrue(page3.getHavePrevious());
    assertNotNull(page3.getRecordCorrections());
    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);
}
Also used : RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) RecordCorrection(org.orcid.model.record_correction.RecordCorrection) Test(org.junit.Test)

Aggregations

RecordCorrectionsPage (org.orcid.model.record_correction.RecordCorrectionsPage)9 Test (org.junit.Test)6 RecordCorrection (org.orcid.model.record_correction.RecordCorrection)4 DBUnitTest (org.orcid.test.DBUnitTest)4 InvalidRecordDataChangeEntity (org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1