Index: src/main/groovy/com/lemanscorp/mqconsumer/config/Resources.groovy =================================================================== diff -u -rbbf2e5405d63748b1584efc46c75fc36f48d22d7 -rcedc0f94d44bda8ede62757754de93e1b35c2af1 --- src/main/groovy/com/lemanscorp/mqconsumer/config/Resources.groovy (.../Resources.groovy) (revision bbf2e5405d63748b1584efc46c75fc36f48d22d7) +++ src/main/groovy/com/lemanscorp/mqconsumer/config/Resources.groovy (.../Resources.groovy) (revision cedc0f94d44bda8ede62757754de93e1b35c2af1) @@ -1,92 +1,101 @@ -package com.lemanscorp.mqconsumer.config - -import javax.sql.DataSource - -import groovy.util.logging.Slf4j -import org.apache.commons.dbcp.BasicDataSource -import org.springframework.amqp.AmqpRejectAndDontRequeueException -import org.springframework.amqp.core.Message -import org.springframework.amqp.rabbit.listener.RabbitListenerErrorHandler -import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException -import org.springframework.amqp.rabbit.retry.MessageRecoverer -import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.boot.context.properties.ConfigurationProperties -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Primary -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.jdbc.datasource.DataSourceTransactionManager -import org.springframework.transaction.support.TransactionTemplate - -@Configuration -@Slf4j -class Resources { - - @Bean - Jackson2JsonMessageConverter converter() { - new Jackson2JsonMessageConverter() - } - - - @Primary - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - BasicDataSource getDefaultDataSource() { - new BasicDataSource() - } - - @Primary - @Bean - NamedParameterJdbcTemplate getNamedParameterJdbcTemplate(DataSource dataSource) { - new NamedParameterJdbcTemplate(dataSource) - } - - @Bean(name = "europeDigiDataSource") - @ConfigurationProperties(prefix = "datasource.eudsdb") - BasicDataSource getEuropeDataSource() { - new BasicDataSource() - } - - @Bean(name = "europeDigiJdbcTemplate") - NamedParameterJdbcTemplate getEuropeJdbcTemplate(@Autowired @Qualifier("europeDigiDataSource") DataSource dataSource) { - new NamedParameterJdbcTemplate(dataSource) - } - - @Bean(name = "europeDigiTransactionTemplate") - TransactionTemplate getTransactionTemplate(@Autowired @Qualifier("europeDigiDataSource") DataSource dataSource) { - new TransactionTemplate(new DataSourceTransactionManager(dataSource)) - } - - @Bean(name = "usToEuErrorHandler") - RabbitListenerErrorHandler usToEuErrorHandler() { - return new RabbitListenerErrorHandler() { - - @Override - Object handleError( - Message amqpMessage, - org.springframework.messaging.Message message, - ListenerExecutionFailedException exception - ) throws Exception { - if (amqpMessage.messageProperties.redelivered && amqpMessage.messageProperties.deliveryTag >= 3) { - throw new AmqpRejectAndDontRequeueException("Already requeue'd 3 times. Sending it to dead-letter-exchange") - } else { - throw exception - } - return null - } - } - } - - @Bean - MessageRecoverer messageRecoverer() { - return new MessageRecoverer() { - - @Override - void recover(Message message, Throwable cause) { - throw new ListenerExecutionFailedException("Retry Policy Exhausted", cause, message) - } - } - } -} +package com.lemanscorp.mqconsumer.config + +import javax.sql.DataSource + +import groovy.util.logging.Slf4j +import org.apache.commons.dbcp.BasicDataSource +import org.springframework.amqp.AmqpRejectAndDontRequeueException +import org.springframework.amqp.core.Message +import org.springframework.amqp.rabbit.listener.RabbitListenerErrorHandler +import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException +import org.springframework.amqp.rabbit.retry.MessageRecoverer +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Primary +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.jdbc.datasource.DataSourceTransactionManager +import org.springframework.transaction.support.TransactionTemplate + +import java.text.SimpleDateFormat + +@Configuration +@Slf4j +class Resources { + + @Bean + Jackson2JsonMessageConverter converter() { + new Jackson2JsonMessageConverter() + } + + + @Primary + @Bean + @ConfigurationProperties(prefix = "spring.datasource") + BasicDataSource getDefaultDataSource() { + new BasicDataSource() + } + + @Primary + @Bean + NamedParameterJdbcTemplate getNamedParameterJdbcTemplate(DataSource dataSource) { + new NamedParameterJdbcTemplate(dataSource) + } + + @Bean(name = "europeDigiDataSource") + @ConfigurationProperties(prefix = "datasource.eudsdb") + BasicDataSource getEuropeDataSource() { + new BasicDataSource() + } + + @Bean(name = "europeDigiJdbcTemplate") + NamedParameterJdbcTemplate getEuropeJdbcTemplate(@Autowired @Qualifier("europeDigiDataSource") DataSource dataSource) { + new NamedParameterJdbcTemplate(dataSource) + } + + @Bean(name = "europeDigiTransactionTemplate") + TransactionTemplate getTransactionTemplate(@Autowired @Qualifier("europeDigiDataSource") DataSource dataSource) { + new TransactionTemplate(new DataSourceTransactionManager(dataSource)) + } + + @Bean(name = "usToEuErrorHandler") + RabbitListenerErrorHandler usToEuErrorHandler() { + return new RabbitListenerErrorHandler() { + + @Override + Object handleError( + Message amqpMessage, + org.springframework.messaging.Message message, + ListenerExecutionFailedException exception + ) throws Exception { + if (amqpMessage.messageProperties.redelivered && amqpMessage.messageProperties.deliveryTag >= 3) { + throw new AmqpRejectAndDontRequeueException("Already requeue'd 3 times. Sending it to dead-letter-exchange") + } else { + throw exception + } + return null + } + } + } + + @Bean + MessageRecoverer messageRecoverer() { + return new MessageRecoverer() { + + @Override + void recover(Message message, Throwable cause) { + throw new ListenerExecutionFailedException("Retry Policy Exhausted", cause, message) + } + } + } + + @Bean + SimpleDateFormat simpleDateFormat() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat() + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+01:00")) + simpleDateFormat + } +} Index: src/main/groovy/com/lemanscorp/mqconsumer/services/CategoryService.groovy =================================================================== diff -u -r176022c00ae6a69ff0e5449aa62eb9101a850d93 -rcedc0f94d44bda8ede62757754de93e1b35c2af1 --- src/main/groovy/com/lemanscorp/mqconsumer/services/CategoryService.groovy (.../CategoryService.groovy) (revision 176022c00ae6a69ff0e5449aa62eb9101a850d93) +++ src/main/groovy/com/lemanscorp/mqconsumer/services/CategoryService.groovy (.../CategoryService.groovy) (revision cedc0f94d44bda8ede62757754de93e1b35c2af1) @@ -3,7 +3,6 @@ import java.sql.ResultSet import com.lemanscorp.mqconsumer.domains.Category -import com.lemanscorp.mqconsumer.domains.CategoryAttributeValue import groovy.util.logging.Slf4j import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier @@ -15,7 +14,7 @@ @Slf4j @Service -class CategoryService { +class CategoryService extends HelperService { @Autowired NamedParameterJdbcTemplate usDigiJdbcTemplate @@ -74,11 +73,11 @@ source: (Integer) rs.getObject("source"), sourceId: (Integer) rs.getObject("sourceId"), effectiveDate: rs.getTimestamp("effectiveDate"), - dateCreated: rs.getTimestamp("dateCreated"), + dateCreated: formatDate(rs.getTimestamp("dateCreated")), createdBy: rs.getString("createdBy"), - lastUpdated: rs.getTimestamp("lastUpdated"), + lastUpdated: formatDate(rs.getTimestamp("lastUpdated")), lastUpdatedBy: rs.getString("lastUpdatedBy"), - dateDeleted: rs.getTimestamp("dateDeleted") ? new Date() : null, + dateDeleted: formatDate(rs.getTimestamp("dateDeleted")) ? formatDate(new Date()) : null, deletedBy: rs.getString("deletedBy"), version: (Integer) rs.getObject("version") ) Index: src/main/groovy/com/lemanscorp/mqconsumer/services/HelperService.groovy =================================================================== diff -u --- src/main/groovy/com/lemanscorp/mqconsumer/services/HelperService.groovy (revision 0) +++ src/main/groovy/com/lemanscorp/mqconsumer/services/HelperService.groovy (revision cedc0f94d44bda8ede62757754de93e1b35c2af1) @@ -0,0 +1,22 @@ +package com.lemanscorp.mqconsumer.services + +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +import java.sql.Timestamp +import java.text.SimpleDateFormat + +@Service +class HelperService { + + @Autowired + SimpleDateFormat simpleDateFormat + + Date formatDate(Timestamp timestamp) { + new Date(simpleDateFormat.format(timestamp)) + } + + Date formatDate(Date date) { + new Date(simpleDateFormat.format(date)) + } +}