Search in sources :

Example 1 with RecordCorrection

use of org.orcid.model.record_correction.RecordCorrection 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 RecordCorrection

use of org.orcid.model.record_correction.RecordCorrection 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)

Example 3 with RecordCorrection

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

the class MapperFacadeFactory method getInvalidRecordDataChangeMapperFacade.

public MapperFacade getInvalidRecordDataChangeMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<RecordCorrection, InvalidRecordDataChangeEntity> classMap = mapperFactory.classMap(RecordCorrection.class, InvalidRecordDataChangeEntity.class);
    classMap.fieldBToA("id", "sequence");
    classMap.fieldBToA("sqlUsedToUpdate", "sqlUsedToUpdate");
    classMap.fieldBToA("description", "description");
    classMap.fieldBToA("numChanged", "numChanged");
    classMap.fieldBToA("type", "type");
    classMap.byDefault();
    classMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) RecordCorrection(org.orcid.model.record_correction.RecordCorrection)

Example 4 with RecordCorrection

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

the class MapperFacadeFactory method getInvalidRecordDataChangeMapperFacade.

public MapperFacade getInvalidRecordDataChangeMapperFacade() {
    MapperFactory mapperFactory = getNewMapperFactory();
    ClassMapBuilder<RecordCorrection, InvalidRecordDataChangeEntity> classMap = mapperFactory.classMap(RecordCorrection.class, InvalidRecordDataChangeEntity.class);
    classMap.fieldBToA("id", "sequence");
    classMap.fieldBToA("sqlUsedToUpdate", "sqlUsedToUpdate");
    classMap.fieldBToA("description", "description");
    classMap.fieldBToA("numChanged", "numChanged");
    classMap.fieldBToA("type", "type");
    classMap.byDefault();
    classMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) RecordCorrection(org.orcid.model.record_correction.RecordCorrection)

Example 5 with RecordCorrection

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

the class JpaJaxbInvalidRecordDataChangeAdapterTest method fromEntityTest.

@Test
public void fromEntityTest() {
    InvalidRecordDataChangeEntity entity = getEntity();
    RecordCorrection element = adapter.toInvalidRecordDataChange(entity);
    assertNotNull(element);
    assertEquals(element.getSequence(), entity.getId());
    assertEquals(element.getDateCreated(), entity.getDateCreated());
    assertEquals(element.getDescription(), entity.getDescription());
    assertEquals(element.getLastModified(), entity.getLastModified());
    assertEquals(element.getNumChanged(), entity.getNumChanged());
    assertEquals(element.getSqlUsedToUpdate(), entity.getSqlUsedToUpdate());
    assertEquals(element.getType(), entity.getType());
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) RecordCorrection(org.orcid.model.record_correction.RecordCorrection) Test(org.junit.Test)

Aggregations

RecordCorrection (org.orcid.model.record_correction.RecordCorrection)7 InvalidRecordDataChangeEntity (org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)5 RecordCorrectionsPage (org.orcid.model.record_correction.RecordCorrectionsPage)4 Test (org.junit.Test)3 MapperFactory (ma.glasnost.orika.MapperFactory)2 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)2 Cacheable (org.springframework.cache.annotation.Cacheable)2