Search in sources :

Example 6 with RecordStatusEntity

use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.

the class RecordStatusDao method get.

public RecordStatusEntity get(String orcid) {
    Query query = entityManager.createNativeQuery("SELECT * FROM record_status WHERE orcid = :orcid", RecordStatusEntity.class);
    query.setParameter("orcid", orcid);
    return (RecordStatusEntity) query.getSingleResult();
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery)

Example 7 with RecordStatusEntity

use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.

the class RecordStatusDaoTest method getTest.

@Test
@Transactional
public void getTest() {
    String orcid = "0000-0000-1000";
    recordStatusDao.create(orcid, AvailableBroker.DUMP_STATUS_1_2_API, 100);
    RecordStatusEntity entity = recordStatusDao.get(orcid);
    assertNotNull(entity);
    assertEquals(orcid, entity.getId());
    assertEquals(Integer.valueOf(100), entity.getDumpStatus12Api());
    assertEquals(Integer.valueOf(0), entity.getDumpStatus20Api());
    assertEquals(Integer.valueOf(0), entity.getSolrStatus20Api());
    assertNotNull(entity.getDateCreated());
    assertNotNull(entity.getLastModified());
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with RecordStatusEntity

use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.

the class RecordStatusDaoTest method getFailedElementsTest.

@Test
@Transactional
public void getFailedElementsTest() {
    recordStatusDao.create("0000-0000-0001-0000", AvailableBroker.DUMP_STATUS_1_2_API, 1);
    recordStatusDao.create("0000-0000-0001-0001", AvailableBroker.DUMP_STATUS_2_0_API, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0002", AvailableBroker.SOLR, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0003", AvailableBroker.DUMP_STATUS_1_2_API, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0004", AvailableBroker.DUMP_STATUS_2_0_API, 1);
    recordStatusDao.create("0000-0000-0001-0005", AvailableBroker.SOLR, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0006", AvailableBroker.DUMP_STATUS_1_2_API, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0007", AvailableBroker.DUMP_STATUS_2_0_API, RecordStatusManager.OK);
    recordStatusDao.create("0000-0000-0001-0008", AvailableBroker.SOLR, 1);
    recordStatusDao.create("0000-0000-0001-0009", AvailableBroker.DUMP_STATUS_1_2_API, RecordStatusManager.OK);
    List<RecordStatusEntity> list = recordStatusDao.getFailedElements(100);
    assertEquals(3, list.size());
    RecordStatusEntity e1 = list.get(0);
    assertEquals("0000-0000-0001-0000", e1.getId());
    assertEquals(Integer.valueOf(1), e1.getDumpStatus12Api());
    assertEquals(Integer.valueOf(0), e1.getDumpStatus20Api());
    assertEquals(Integer.valueOf(0), e1.getSolrStatus20Api());
    RecordStatusEntity e2 = list.get(1);
    assertEquals("0000-0000-0001-0004", e2.getId());
    assertEquals(Integer.valueOf(0), e2.getDumpStatus12Api());
    assertEquals(Integer.valueOf(1), e2.getDumpStatus20Api());
    assertEquals(Integer.valueOf(0), e2.getSolrStatus20Api());
    RecordStatusEntity e3 = list.get(2);
    assertEquals("0000-0000-0001-0008", e3.getId());
    assertEquals(Integer.valueOf(0), e3.getDumpStatus12Api());
    assertEquals(Integer.valueOf(0), e3.getDumpStatus20Api());
    assertEquals(Integer.valueOf(1), e3.getSolrStatus20Api());
    list = recordStatusDao.getFailedElements(2);
    assertEquals(2, list.size());
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with RecordStatusEntity

use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.

the class RecordStatusManagerTest method setSentThenFailedThenSentAgainTest.

@Test
public void setSentThenFailedThenSentAgainTest() {
    String orcid = "0000-0000-0000-0003";
    //First mark it as sent
    assertFalse(recordStatusDao.exists(orcid));
    recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    assertTrue(recordStatusDao.exists(orcid));
    RecordStatusEntity entity = recordStatusDao.get(orcid);
    assertNotNull(entity);
    assertEquals(orcid, entity.getId());
    assertEquals(Integer.valueOf(0), entity.getDumpStatus12Api());
    //Then make it fail 3 times
    recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    //Verify it's status is 3
    entity = recordStatusDao.get(orcid);
    assertNotNull(entity);
    assertEquals(orcid, entity.getId());
    assertEquals(Integer.valueOf(3), entity.getDumpStatus12Api());
    //Then mark it as sent
    recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    //Verify it's status was cleared 
    entity = recordStatusDao.get(orcid);
    assertNotNull(entity);
    assertEquals(orcid, entity.getId());
    assertEquals(Integer.valueOf(0), entity.getDumpStatus12Api());
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) Test(org.junit.Test)

Example 10 with RecordStatusEntity

use of org.orcid.listener.persistence.entities.RecordStatusEntity in project ORCID-Source by ORCID.

the class RecordStatusManagerTest method markAsSentTest.

@Test
public void markAsSentTest() {
    String orcid = "0000-0000-0000-0001";
    assertFalse(recordStatusDao.exists(orcid));
    recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    assertTrue(recordStatusDao.exists(orcid));
    RecordStatusEntity entity = recordStatusDao.get(orcid);
    assertNotNull(entity);
    assertEquals(orcid, entity.getId());
    assertEquals(Integer.valueOf(0), entity.getDumpStatus12Api());
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) Test(org.junit.Test)

Aggregations

RecordStatusEntity (org.orcid.listener.persistence.entities.RecordStatusEntity)10 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 Before (org.junit.Before)1 RetryMessage (org.orcid.utils.listener.RetryMessage)1 JmsException (org.springframework.jms.JmsException)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1