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;
}
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();
}
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();
}
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;
}
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());
}
Aggregations