Search in sources :

Example 1 with InvalidRecordDataChangeEntity

use of org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity 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 InvalidRecordDataChangeEntity

use of org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity in project ORCID-Source by ORCID.

the class RecordCorrectionsManagerReadOnlyTest method before.

/**
     * Simulates a list of 10 record corrections from 1 to 10.     
     * */
@Before
public void before() {
    MockitoAnnotations.initMocks(this);
    TargetProxyHelper.injectIntoProxy(manager, "dao", dao);
    when(dao.getByDateCreated(ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).then(new Answer<List<InvalidRecordDataChangeEntity>>() {

        @Override
        public List<InvalidRecordDataChangeEntity> answer(InvocationOnMock invocation) throws Throwable {
            Long first = (Long) invocation.getArgument(0);
            Long size = (Long) invocation.getArgument(1);
            Boolean order = (Boolean) invocation.getArgument(2);
            List<InvalidRecordDataChangeEntity> elements = new ArrayList<InvalidRecordDataChangeEntity>();
            if (order) {
                for (long i = first; i > (first - size); i--) {
                    if (i < 1) {
                        break;
                    }
                    InvalidRecordDataChangeEntity element = new InvalidRecordDataChangeEntity();
                    element.setDateCreated(new Date());
                    element.setDescription("description " + i);
                    element.setId(Long.valueOf(i));
                    element.setLastModified(new Date());
                    element.setNumChanged(Long.valueOf(i));
                    element.setSqlUsedToUpdate("select * from table");
                    element.setType("type " + i);
                    elements.add(element);
                }
            } else {
                for (long i = first; i < (first + size); i++) {
                    if (i > 10) {
                        break;
                    }
                    InvalidRecordDataChangeEntity element = new InvalidRecordDataChangeEntity();
                    element.setDateCreated(new Date());
                    element.setDescription("description " + i);
                    element.setId(Long.valueOf(i));
                    element.setLastModified(new Date());
                    element.setNumChanged(Long.valueOf(i));
                    element.setSqlUsedToUpdate("select * from table");
                    element.setType("type " + i);
                    elements.add(element);
                }
            }
            return elements;
        }
    });
    when(dao.haveNext(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Long sequence = (Long) invocation.getArgument(0);
            Boolean order = (Boolean) invocation.getArgument(1);
            if (order) {
                if (sequence <= 1L) {
                    return false;
                }
            } else {
                if (sequence >= 10) {
                    return false;
                }
            }
            return true;
        }
    });
    when(dao.havePrevious(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Long sequence = (Long) invocation.getArgument(0);
            Boolean order = (Boolean) invocation.getArgument(1);
            if (order) {
                if (sequence >= 10L) {
                    return false;
                }
            } else {
                if (sequence <= 1L) {
                    return false;
                }
            }
            return true;
        }
    });
    manager.cacheEvict();
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) Before(org.junit.Before)

Example 3 with InvalidRecordDataChangeEntity

use of org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity 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 InvalidRecordDataChangeEntity

use of org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity in project ORCID-Source by ORCID.

the class JpaJaxbInvalidRecordDataChangeAdapterTest method getEntity.

private InvalidRecordDataChangeEntity getEntity() {
    InvalidRecordDataChangeEntity entity = new InvalidRecordDataChangeEntity();
    entity.setDateCreated(date);
    entity.setDescription("description");
    entity.setId(1234L);
    entity.setLastModified(date);
    entity.setNumChanged(24816L);
    entity.setSqlUsedToUpdate("update table set data = 'value' where key = key");
    entity.setType("type");
    return entity;
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)

Example 5 with InvalidRecordDataChangeEntity

use of org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity in project ORCID-Source by ORCID.

the class InvalidRecordDataChangeDaoTest method fetchAllDescendantTest.

@Test
public void fetchAllDescendantTest() {
    List<InvalidRecordDataChangeEntity> onePage = dao.getByDateCreated(null, 16L, true);
    assertNotNull(onePage);
    assertEquals(16, onePage.size());
    // Assert the first one
    assertEquals(Long.valueOf(1015), onePage.get(0).getId());
    // Assert the last one
    assertEquals(Long.valueOf(1000), onePage.get(15).getId());
    Iterator<InvalidRecordDataChangeEntity> it = onePage.iterator();
    Long initial = null;
    Long next = null;
    // Verify they respect the descendant ordered
    do {
        InvalidRecordDataChangeEntity current = it.next();
        if (initial == null) {
            initial = current.getId();
            continue;
        }
        next = current.getId();
        assertTrue((initial - 1L) == next);
        initial = next;
        next = null;
    } while (it.hasNext());
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Aggregations

InvalidRecordDataChangeEntity (org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)10 RecordCorrection (org.orcid.model.record_correction.RecordCorrection)4 Test (org.junit.Test)3 RecordCorrectionsPage (org.orcid.model.record_correction.RecordCorrectionsPage)2 DBUnitTest (org.orcid.test.DBUnitTest)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1