Search in sources :

Example 1 with AggregationCompleted

use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository method recover.

/**
	 * {@inheritDoc}
	 * This specific implementation locks the recovered exchange for a period of time specified by the DAO.
	 * If the exchange is locked by the DAO, then null is returned.
	 */
@Override
public Exchange recover(CamelContext camelContext, String exchangeId) {
    Exchange retVal = null;
    try {
        // recover the exchnage from the repository
        final AggregationCompleted agg = dao.getAggregationCompleted(exchangeId, true);
        // not found or is locked... return null
        if (agg == null)
            return null;
        // deserialize exchange 
        retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
        // set the version number of the exchange
        retVal.setProperty(AGGREGATION_COMPLETE_ENTITY_VERSON, agg.getVersion());
    } catch (Exception e) {
        // wrap exception in a runtime exception
        throw new RuntimeException("Error recovering exchange from repository with exchangeId " + exchangeId, e);
    }
    return retVal;
}
Also used : Exchange(org.apache.camel.Exchange) Buffer(org.fusesource.hawtbuf.Buffer) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted)

Example 2 with AggregationCompleted

use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_emptyRepository_assertNoAggregation.

@Test
public void testGetAggregationCompleted_emptyRepository_assertNoAggregation() throws Exception {
    final AggregationCompleted aggr = notifDao.getAggregationCompleted("doenst matter", true);
    assertNull(aggr);
}
Also used : AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) Test(org.junit.Test)

Example 3 with AggregationCompleted

use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound.

@Test
public void testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound() throws Exception {
    EntityManager mgr = mock(EntityManager.class);
    doThrow(new OptimisticLockException()).when(mgr).find((Class<?>) any(), any());
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    final AggregationCompleted lockedAggr = dao.getAggregationCompleted("12345", true);
    assertNull(lockedAggr);
}
Also used : EntityManager(javax.persistence.EntityManager) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 4 with AggregationCompleted

use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.

the class AggregationDAOImpl_removeAggregationTest method testRemoveAggregation_removeAggregation_assertRemovedAndCompletedRepositry.

@Test
public void testRemoveAggregation_removeAggregation_assertRemovedAndCompletedRepositry() throws Exception {
    final Aggregation insert = new Aggregation();
    insert.setExchangeBlob(new byte[] { 0, 3, 2 });
    insert.setId("12345");
    insert.setVersion(0);
    notifDao.addUpdateAggregation(insert);
    assertNotNull(notifDao.getAggregation("12345"));
    final Aggregation remove = new Aggregation();
    remove.setExchangeBlob(new byte[] { 0, 3, 2 });
    remove.setId("12345");
    remove.setVersion(1);
    notifDao.removeAggregation(remove, "12345");
    assertNull(notifDao.getAggregation("12345"));
    final AggregationCompleted completed = notifDao.getAggregationCompleted("12345", true);
    assertNotNull(completed);
    assertEquals("12345", completed.getId());
    assertEquals(3, completed.getVersion());
    assertTrue(Arrays.equals(remove.getExchangeBlob(), completed.getExchangeBlob()));
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) Test(org.junit.Test)

Example 5 with AggregationCompleted

use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.

the class AggregationDAOImpl method confirmAggregation.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void confirmAggregation(String id) throws AggregationDAOException {
    try {
        // find the aggregation
        final AggregationCompleted completed = entityManager.find(AggregationCompleted.class, id);
        if (completed != null) {
            // remove it
            entityManager.remove(completed);
            entityManager.flush();
        }
    } catch (Exception e) {
        throw new AggregationDAOException("Failed to confirm aggregation.", e);
    }
}
Also used : AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationVersionException(org.nhindirect.monitor.dao.AggregationVersionException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AggregationCompleted (org.nhindirect.monitor.dao.entity.AggregationCompleted)11 Test (org.junit.Test)7 Aggregation (org.nhindirect.monitor.dao.entity.Aggregation)6 OptimisticLockException (javax.persistence.OptimisticLockException)4 AggregationDAOException (org.nhindirect.monitor.dao.AggregationDAOException)3 AggregationVersionException (org.nhindirect.monitor.dao.AggregationVersionException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Calendar (java.util.Calendar)1 EntityManager (javax.persistence.EntityManager)1 Exchange (org.apache.camel.Exchange)1 Buffer (org.fusesource.hawtbuf.Buffer)1 AggregationDAOImpl (org.nhindirect.monitor.dao.impl.AggregationDAOImpl)1