Example usage for javax.jms TextMessage getText

List of usage examples for javax.jms TextMessage getText

Introduction

In this page you can find the example usage for javax.jms TextMessage getText.

Prototype


String getText() throws JMSException;

Source Link

Document

Gets the string containing this message's data.

Usage

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects a message after each 3 received messages and then wait
 * for the redelivered message.//from ww w. ja v  a  2 s. com
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 * Here message receive method is used instead of the message listener to receive messages.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void oneByOneUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    long sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "oneByOneUnacknowledgeReceiverQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeReceiverQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    final MessageConsumer receiver = andesJMSConsumer.getReceiver();
    Thread messageReceivingThread = new Thread() {
        public void run() {
            while (receiver != null) {
                try {
                    TextMessage textMessage = (TextMessage) receiver.receive();
                    if (Integer.parseInt(textMessage.getText().split("#")[1]) % 3 != 0
                            || getMessageList(receivedMessages).contains(textMessage.getText())) {
                        textMessage.acknowledge();
                    }
                    receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                    andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
                } catch (JMSException e) {
                    throw new RuntimeException("Exception occurred when receiving messages.", e);
                }
            }
        }
    };
    messageReceivingThread.start();
    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount; i++) {
        Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                "Invalid messages received. #" + Integer.toString(i) + " expected.");
    }

    validateMessageContentAndDelay(receivedMessages, 0, 10, "#0");
    validateMessageContentAndDelay(receivedMessages, 1, 11, "#3");
    validateMessageContentAndDelay(receivedMessages, 2, 12, "#6");
    validateMessageContentAndDelay(receivedMessages, 3, 13, "#9");

    Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed.");
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects first 4 messages and then wait for the redelivered
 * message./* w  w w  . jav  a2s  .c  o  m*/
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 * Here message receive method is used instead of the message listener to receive messages.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void firstFewUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    long sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "firstFewUnacknowledgeReceiverQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "firstFewUnacknowledgeReceiverQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    final MessageConsumer receiver = andesJMSConsumer.getReceiver();
    Thread messageReceivingThread = new Thread() {
        public void run() {
            while (receiver != null) {
                try {
                    TextMessage textMessage = (TextMessage) receiver.receive();
                    if (Integer.parseInt(textMessage.getText().split("#")[1]) >= 4
                            || getMessageList(receivedMessages).contains(textMessage.getText())) {
                        textMessage.acknowledge();
                    }
                    receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                    andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
                } catch (JMSException e) {
                    throw new RuntimeException("Exception occurred when receiving messages.", e);
                }
            }
        }
    };
    messageReceivingThread.start();
    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount; i++) {
        Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                "Invalid messages received. #" + Integer.toString(i) + " expected.");
    }

    validateMessageContentAndDelay(receivedMessages, 0, 10, "#0");
    validateMessageContentAndDelay(receivedMessages, 1, 11, "#1");
    validateMessageContentAndDelay(receivedMessages, 2, 12, "#2");
    validateMessageContentAndDelay(receivedMessages, 3, 13, "#3");

    Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed.");
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects the first message and then wait for the redelivered
 * message.//from w w w  . j av a  2 s  .co m
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void firstMessageInvalidOnlyQueueMessageListenerTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    long sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();
    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "firstMessageInvalidOnlyQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);
    publisherConfig.setPrintsPerMessageCount(sendCount / 10L);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    MessageConsumer receiver = andesJMSConsumer.getReceiver();
    receiver.setMessageListener(new MessageListener() {
        private boolean receivedFirstMessage = false;

        @Override
        public void onMessage(Message message) {
            try {
                TextMessage textMessage = (TextMessage) message;
                if (!receivedFirstMessage && "#0".equals(textMessage.getText())) {
                    receivedFirstMessage = true;
                } else {
                    message.acknowledge();
                }
                receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
            } catch (JMSException e) {
                throw new RuntimeException("Exception occurred when receiving messages.", e);
            }
        }
    });

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount; i++) {
        Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                "Invalid messages received. #" + Integer.toString(i) + " expected.");
    }

    validateMessageContentAndDelay(receivedMessages, 0, 10, "#0");

    Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed.");
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 1000 messages and the subscriber reject each 100th message and then wait for the redelivered
 * message.// w ww .java 2  s .  c  o  m
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 * Here message receive method is used instead of the message listener to receive messages.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void oneByOneUnacknowledgeMessageReceiverForMultipleMessagesTestCase()
        throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException,
        AndesClientException, NamingException {
    long sendCount = 1000;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "oneByOneUnacknowledgeMessageReceiverForMultipleQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeMessageReceiverForMultipleQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    final MessageConsumer receiver = andesJMSConsumer.getReceiver();
    Thread messageReceivingThread = new Thread() {
        public void run() {
            while (receiver != null) {
                try {
                    TextMessage textMessage = (TextMessage) receiver.receive();
                    if (Integer.parseInt(textMessage.getText().split("#")[1]) % 100 != 0
                            || getMessageList(receivedMessages).contains(textMessage.getText())) {
                        textMessage.acknowledge();
                    }
                    receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                    andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
                } catch (JMSException e) {
                    throw new RuntimeException("Exception occurred when receiving messages.", e);
                }
            }
        }
    };
    messageReceivingThread.start();
    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME * 2);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount; i++) {
        Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                "Invalid messages received. #" + Integer.toString(i) + " expected.");
    }

    validateMessageContentAndDelay(receivedMessages, 0, 1000, "#0");
    validateMessageContentAndDelay(receivedMessages, 99, 1001, "#100");
    validateMessageContentAndDelay(receivedMessages, 199, 1002, "#200");
    validateMessageContentAndDelay(receivedMessages, 299, 1003, "#300");
    validateMessageContentAndDelay(receivedMessages, 399, 1004, "#400");
    validateMessageContentAndDelay(receivedMessages, 499, 1005, "#500");
    validateMessageContentAndDelay(receivedMessages, 599, 1006, "#600");
    validateMessageContentAndDelay(receivedMessages, 699, 1007, "#700");
    validateMessageContentAndDelay(receivedMessages, 799, 1008, "#800");
    validateMessageContentAndDelay(receivedMessages, 899, 1009, "#900");

    Assert.assertEquals(receivedMessages.size(), sendCount + 10, "Message receiving failed.");
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects all message and then wait for the redelivered
 * message.//from   ww w  . j a v a2s.  co m
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void allUnacknowledgeMessageListenerTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    int sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "multipleUnacknowledgeQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    MessageConsumer receiver = andesJMSConsumer.getReceiver();
    receiver.setMessageListener(new MessageListener() {
        @Override
        public void onMessage(Message message) {
            try {
                TextMessage textMessage = (TextMessage) message;
                if (getMessageList(receivedMessages).contains(textMessage.getText())) {
                    message.acknowledge();
                }
                receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
            } catch (JMSException e) {
                throw new RuntimeException("Exception occurred when receiving messages.", e);
            }
        }
    });

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount * 2; i++) {
        if (i < sendCount) {
            Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                    "Invalid messages received. #" + Integer.toString(i) + " expected.");
        } else {
            validateMessageContentAndDelay(receivedMessages, i - sendCount, i,
                    "#" + Integer.toString(i - sendCount));
        }
    }

    Assert.assertEquals(receivedMessages.size(), sendCount * 2, "Message receiving failed.");
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects the first message and then wait for the redelivered
 * message./*from ww  w. j  a  v a2s  .  c o m*/
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 * Here message receive method is used instead of the message listener to receive messages.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void firstMessageInvalidOnlyQueueMessageReceiverTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    long sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();
    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "firstMessageInvalidOnlyReceiverQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyReceiverQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);
    publisherConfig.setPrintsPerMessageCount(sendCount / 10L);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    final MessageConsumer receiver = andesJMSConsumer.getReceiver();
    Thread messageReceivingThread = new Thread() {
        private boolean receivedFirstMessage = false;

        public void run() {
            while (receiver != null) {
                try {
                    TextMessage textMessage = (TextMessage) receiver.receive();
                    if (!receivedFirstMessage && "#0".equals(textMessage.getText())) {
                        receivedFirstMessage = true;
                    } else {
                        textMessage.acknowledge();
                    }
                    receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                    andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
                } catch (JMSException e) {
                    throw new RuntimeException("Exception occurred when receiving messages.", e);
                }
            }
        }
    };
    messageReceivingThread.start();
    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }
    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));
    for (int i = 0; i < sendCount; i++) {
        Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                "Invalid messages received. #" + Integer.toString(i) + " expected.");
    }

    validateMessageContentAndDelay(receivedMessages, 0, 10, "#0");

    Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed.");

}

From source file:org.wso2.mb.integration.common.clients.operations.topic.TopicMessageReceiver.java

public void run() {
    try {/*from   w  w  w .ja  v  a2 s.  c  o m*/
        if (useMessageListener) {
            TopicMessageListener messageListener = new TopicMessageListener(topicConnection, topicSession,
                    topicSubscriber, topicName, subscriptionId, messageCounter, delayBetweenMessages,
                    printNumberOfMessagesPer, isToPrintEachMessage, fileToWriteReceivedMessages, stopAfter,
                    unSubscribeAfter, ackAfterEach, rollbackAfterEach, commitAfterEach);
            topicSubscriber.setMessageListener(messageListener);
        } else {

            int localMessageCount = 0;
            while (true) {
                Message message = topicSubscriber.receive();
                if (message != null && message instanceof TextMessage) {
                    messageCounter.incrementAndGet();
                    localMessageCount++;
                    String redelivery;
                    TextMessage textMessage = (TextMessage) message;
                    if (message.getJMSRedelivered()) {
                        redelivery = "REDELIVERED";
                    } else {
                        redelivery = "ORIGINAL";
                    }
                    if (messageCounter.get() % printNumberOfMessagesPer == 0) {
                        log.info("[TOPIC RECEIVE] ThreadID:" + Thread.currentThread().getId() + " topic:"
                                + topicName + " localMessageCount:" + localMessageCount + " totalMessageCount:"
                                + messageCounter.get() + " max count:" + stopAfter);
                    }
                    if (isToPrintEachMessage) {
                        log.info("(count:" + messageCounter.get() + "/threadID:"
                                + Thread.currentThread().getId() + "/topic:" + topicName + ") " + redelivery
                                + " >> " + textMessage.getText());
                        AndesClientUtils.writeToFile(textMessage.getText(), fileToWriteReceivedMessages);
                    }
                }

                if (messageCounter.get() % ackAfterEach == 0) {
                    if (topicSession.getAcknowledgeMode() == QueueSession.CLIENT_ACKNOWLEDGE) {
                        if (message != null) {
                            message.acknowledge();
                        }
                    }
                }

                //commit get priority
                if (messageCounter.get() % commitAfterEach == 0) {
                    topicSession.commit();
                    log.info("Committed session");
                } else if (messageCounter.get() % rollbackAfterEach == 0) {
                    topicSession.rollback();
                    log.info("Rollbacked session");
                }

                if (messageCounter.get() >= unSubscribeAfter) {
                    unsubscribe();
                    break;
                } else if (messageCounter.get() >= stopAfter) {
                    stopListening();
                    break;
                }

                if (delayBetweenMessages != 0) {
                    try {
                        Thread.sleep(delayBetweenMessages);
                    } catch (InterruptedException e) {
                        //silently ignore
                    }
                }
            }
        }
    } catch (JMSException e) {
        log.error("Error while listening for messages", e);
    }
}

From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java

/**
 * This test publishes 10 messages and the subscriber rejects all message and then wait for the redelivered
 * message.//from   ww  w  . j a  v  a2  s.c  om
 * <p/>
 * The redelivered message is tested against the same message content with the original message and the timestamps
 * are also checked against the original message timestamp to make sure that the message was delayed.
 * Here message receive method is used instead of the message listener to receive messages.
 *
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
@Test(groups = { "wso2.mb", "queue" })
public void allUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException,
        XPathExpressionException, IOException, JMSException, AndesClientException, NamingException {
    int sendCount = 10;
    final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, "multipleUnacknowledgeReceiverQueue");
    consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeReceiverQueue");
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0);
    final MessageConsumer receiver = andesJMSConsumer.getReceiver();
    Thread messageReceivingThread = new Thread() {
        public void run() {
            while (receiver != null) {
                try {
                    TextMessage textMessage = (TextMessage) receiver.receive();
                    if (getMessageList(receivedMessages).contains(textMessage.getText())) {
                        textMessage.acknowledge();
                    }
                    receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance()));
                    andesJMSConsumer.getReceivedMessageCount().incrementAndGet();
                } catch (JMSException e) {
                    throw new RuntimeException("Exception occurred when receiving messages.", e);
                }
            }
        }
    };
    messageReceivingThread.start();
    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0);
    MessageProducer sender = andesJMSPublisher.getSender();
    for (int i = 0; i < sendCount; i++) {
        TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i));
        sender.send(textMessage);
    }

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);
    log.info("Received Messages : " + getMessageList(receivedMessages));

    for (int i = 0; i < sendCount * 2; i++) {
        if (i < sendCount) {
            Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i),
                    "Invalid messages received. #" + Integer.toString(i) + " expected.");
        } else {
            validateMessageContentAndDelay(receivedMessages, i - sendCount, i,
                    "#" + Integer.toString(i - sendCount));
        }
    }

    Assert.assertEquals(receivedMessages.size(), sendCount * 2, "Message receiving failed.");
}

From source file:com.inkubator.hrm.service.impl.NotificationApprovalMessagesListener.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//  w  ww .java2s  . com
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class)
public void onMessage(Message message) {
    try {
        LOGGER.info("Begin Send Email Approval");
        TextMessage textMessage = (TextMessage) message;
        String json = textMessage.getText();
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd-MMMM-yyyy");
        Gson gson = gsonBuilder.create();
        Gson gsonDateSerializer = JsonUtil.getHibernateEntityGsonBuilder()
                .registerTypeAdapter(Date.class, new DateJsonDeserializer()).create();
        JsonObject jsonObject = (JsonObject) gson.fromJson(json, JsonObject.class);
        String locale = jsonObject.get("locale").getAsString();

        ApprovalActivity appActivity = approvalActivityDao
                .getEntiyByPK(jsonObject.get("approvalActivityId").getAsLong());

        HrmUser approverUser = hrmUserDao.getByUserId(appActivity.getApprovedBy());
        HrmUser requesterUser = hrmUserDao.getByUserId(appActivity.getRequestBy());

        VelocityTempalteModel vtm = new VelocityTempalteModel();
        List<String> toSend = new ArrayList<>();
        List<String> toSentCC = new ArrayList<String>();
        List<String> toSentBCC = new ArrayList<String>();

        vtm.setFrom(ownerEmail);
        /*if(appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_WAITING) {
         //kirim email ke approver nya jika status waiting
         toSend.add(approverUser.getEmailAddress()); 
         } else if(appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_CANCELLED){
         //kirim email ke approver nya jika status cancelled. Dan cc email ke requester
         toSend.add(approverUser.getEmailAddress());
         toSentCC.add(requesterUser.getEmailAddress());
         } else if((appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_APPROVED) && appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_REJECTED) {
         //kirim email ke requester nya jika statusnya sudah di approved/rejected. Dan cc email (if any)
         toSend.add(requesterUser.getEmailAddress()); 
         for(JsonElement el:jsonObject.get("ccEmailAddresses").getAsJsonArray()){
         toSentCC.add(el.getAsString());
         }
         }*/
        toSend.add("deni.arianto1606@gmail.com");
        toSend.add("rizal2_dhfr@yahoo.com");
        //            toSend.add("yosa.mareta@gmail.com");
        toSend.add("guntur@incubatechnology.com");
        toSentCC.add("rizkykojek@gmail.com");
        toSentCC.add("amjadicky@gmail.com");
        vtm.setTo(toSend.toArray(new String[toSend.size()]));
        vtm.setCc(toSentCC.toArray(new String[toSentCC.size()]));
        vtm.setBcc(toSentBCC.toArray(new String[toSentBCC.size()]));

        Map maptoSend = new HashMap();
        if (StringUtils.equals(locale, "en")) {
            //not yet implemented

        } else {
            if (Objects.equals(appActivity.getApprovalStatus(), HRMConstant.APPROVAL_STATUS_WAITING_APPROVAL)) {
                //configure email parameter based on approval name
                switch (appActivity.getApprovalDefinition().getName()) {
                case HRMConstant.VACANCY_ADVERTISEMENT:
                    List<VacancyAdvertisementDetailModel> listAdvertisementDetail = gsonDateSerializer.fromJson(
                            jsonObject.get("listAdvertisementDetail").getAsString(),
                            new TypeToken<List<VacancyAdvertisementDetailModel>>() {
                            }.getType());

                    vtm.setSubject("Pengajuan Iklan Lowongan");
                    vtm.setTemplatePath("email_vacancy_advertisement_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("effectiveDate", jsonObject.get("effectiveDate").getAsString());
                    maptoSend.put("advertisementMediaName",
                            jsonObject.get("advertisementMediaName").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("listAdvertisementDetail", listAdvertisementDetail);
                    maptoSend.put("dateTool", new DateTool());
                    maptoSend.put("numTool", new NumberTool());
                    maptoSend.put("locale", new Locale(locale));
                    break;

                case HRMConstant.EMP_CORRECTION_ATTENDANCE:
                    List<WtEmpCorrectionAttendanceDetail> listCorrectionAttendance = gsonDateSerializer
                            .fromJson(jsonObject.get("listCorrectionAttendance").getAsString(),
                                    new TypeToken<List<WtEmpCorrectionAttendanceDetail>>() {
                                    }.getType());

                    vtm.setTemplatePath("email_correction_attendance_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("listCorrectionAttendance", listCorrectionAttendance);
                    maptoSend.put("dateTool", new DateTool());
                    maptoSend.put("locale", new Locale(locale));
                    break;

                case HRMConstant.BUSINESS_TRAVEL:
                    vtm.setSubject("Permohonan Perjalanan Dinas");
                    vtm.setTemplatePath("email_travel_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("businessTravelNo", jsonObject.get("businessTravelNo").getAsString());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("destination", jsonObject.get("destination").getAsString());
                    maptoSend.put("start", jsonObject.get("startDate").getAsString());
                    maptoSend.put("end", jsonObject.get("endDate").getAsString());
                    maptoSend.put("description", jsonObject.get("description").getAsString());
                    maptoSend.put("totalAmount", jsonObject.get("totalAmount").getAsString());
                    maptoSend.put("deadline", jsonObject.get("deadline").getAsString());

                    break;

                case HRMConstant.REIMBURSEMENT:
                    vtm.setSubject("Permohonan Penggantian Biaya");
                    vtm.setTemplatePath("email_reimbursment_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("reimbursementType", jsonObject.get("reimbursementType").getAsString());
                    maptoSend.put("applicationDate", jsonObject.get("applicationDate").getAsString());
                    maptoSend.put("nominal", jsonObject.get("nominal").getAsString());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("deadline", jsonObject.get("deadline").getAsString());

                    break;

                case HRMConstant.REIMBURSEMENT_DISBURSEMENT:
                    vtm.setSubject("Permohonan Pencairan Penggantian Biaya");
                    vtm.setTemplatePath("email_rmbs_disbursement_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("deadline", jsonObject.get("deadline").getAsString());
                    break;

                case HRMConstant.LOAN:
                    vtm.setSubject("Permohonan Pinjaman Lunak");
                    vtm.setTemplatePath("email_loan_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("loanSchemaName", jsonObject.get("loanSchemaName").getAsString());
                    maptoSend.put("nominalPrincipal", jsonObject.get("nominalPrincipal").getAsString());
                    maptoSend.put("interestRate", jsonObject.get("interestRate").getAsString());
                    maptoSend.put("nominalInstallment", jsonObject.get("nominalInstallment").getAsString());
                    maptoSend.put("interestInstallment", jsonObject.get("interestInstallment").getAsString());
                    maptoSend.put("totalNominalInstallment",
                            jsonObject.get("totalNominalInstallment").getAsString());
                    break;

                case HRMConstant.SHIFT_SCHEDULE:
                    vtm.setSubject("Permohonan Perubahan Jadwal Kerja Karyawan");
                    vtm.setTemplatePath("email_shift_schedule_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("jabatan", requesterUser.getEmpData().getJabatanByJabatanId().getName());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    break;

                case HRMConstant.LEAVE:
                    vtm.setSubject("Permohonan Cuti");
                    vtm.setTemplatePath("email_leave_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("leaveName", jsonObject.get("leaveName").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("fillingDate", jsonObject.get("fillingDate").getAsString());
                    maptoSend.put("materialJobsAbandoned",
                            jsonObject.get("materialJobsAbandoned").getAsString());
                    break;

                case HRMConstant.LEAVE_CANCELLATION:
                    vtm.setSubject("Permohonan Pembatalan Cuti");
                    vtm.setTemplatePath("email_leave_cancellation_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("leaveName", jsonObject.get("leaveName").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("fillingDate", jsonObject.get("fillingDate").getAsString());
                    maptoSend.put("materialJobsAbandoned",
                            jsonObject.get("materialJobsAbandoned").getAsString());
                    maptoSend.put("cancellationDate", jsonObject.get("cancellationDate").getAsString());
                    break;

                case HRMConstant.OVERTIME:
                    vtm.setSubject("Permohonan Lembur");
                    vtm.setTemplatePath("email_overtime_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("overTimeName", jsonObject.get("overTimeName").getAsString());
                    maptoSend.put("hour", jsonObject.get("hour").getAsString());
                    maptoSend.put("minute", jsonObject.get("minute").getAsString());
                    maptoSend.put("overTimeDate", jsonObject.get("overTimeDate").getAsString());
                    maptoSend.put("implementationNumber", jsonObject.get("implementationNumber").getAsString());
                    break;

                case HRMConstant.ANNOUNCEMENT:
                    TypeToken<List<String>> token = new TypeToken<List<String>>() {
                    };
                    List<String> dataGolonganJabatan = gson.fromJson(jsonObject.get("listGolonganJabatan"),
                            token.getType());
                    List<String> dataUnitKerja = gson.fromJson(jsonObject.get("listUnitKerja"),
                            token.getType());
                    List<String> dataEmployeeType = gson.fromJson(jsonObject.get("listEmployeeType"),
                            token.getType());

                    vtm.setSubject("Pengajuan Pengumuman");
                    vtm.setTemplatePath("email_announcement_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("subjek", jsonObject.get("subjek").getAsString());
                    maptoSend.put("content", jsonObject.get("content").getAsString());
                    maptoSend.put("company", jsonObject.get("company").getAsString());
                    maptoSend.put("listEmployeeType", dataEmployeeType);
                    maptoSend.put("listUnitKerja", dataUnitKerja);
                    maptoSend.put("listGolonganJabatan", dataGolonganJabatan);
                    break;
                case HRMConstant.PERMIT:
                    vtm.setSubject("Permohonan Izin");
                    vtm.setTemplatePath("email_permit_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("permitClassification", jsonObject.get("permitClassification").getAsString());
                    break;
                case HRMConstant.RECRUITMENT_REQUEST:
                    vtm.setSubject("PENGAJUAN PERMINTAAN TENAGA KERJA");
                    vtm.setTemplatePath("email_recruitment_request_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("periodeStart", jsonObject.get("periodeStart").getAsString());
                    maptoSend.put("periodeEnd", jsonObject.get("periodeEnd").getAsString());
                    maptoSend.put("jabatan", jsonObject.get("jabatan").getAsString());
                    maptoSend.put("mppName", jsonObject.get("mppName").getAsString());
                    maptoSend.put("salaryMin", jsonObject.get("salaryMin").getAsString());
                    maptoSend.put("salaryMax", jsonObject.get("salaryMax").getAsString());
                    maptoSend.put("candidateCountRequest",
                            jsonObject.get("candidateCountRequest").getAsString());
                    break;
                case HRMConstant.RECRUIT_MPP_APPLY:
                    TypeToken<List<String>> token2 = new TypeToken<List<String>>() {
                    };
                    List<String> listNamaJabatan = gson.fromJson(jsonObject.get("listNamaJabatan"),
                            token2.getType());

                    vtm.setSubject("PERSETUJUAN RENCANA KETENAGAKERJAAN");
                    vtm.setTemplatePath("email_mpp_apply_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("recruitMppApplyName", jsonObject.get("recruitMppApplyName").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("listNamaJabatan", listNamaJabatan);
                    break;
                case HRMConstant.EMPLOYEE_CAREER_TRANSITION:
                    vtm.setSubject("Pengajuan Transisi Karir");
                    vtm.setTemplatePath("email_career_transition_waiting_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("beforeNik", jsonObject.get("beforeNik").getAsString());
                    maptoSend.put("beforeJoinDate", jsonObject.get("beforeJoinDate").getAsString());
                    maptoSend.put("beforeEmployeeType", jsonObject.get("beforeEmployeeType").getAsString());
                    maptoSend.put("beforeJabatan", jsonObject.get("beforeJabatan").getAsString());
                    maptoSend.put("beforeDepartment", jsonObject.get("beforeDepartment").getAsString());
                    maptoSend.put("afterNik", jsonObject.get("afterNik").getAsString());
                    maptoSend.put("afterJoinDate", jsonObject.get("afterJoinDate").getAsString());
                    maptoSend.put("afterEmployeeType", jsonObject.get("afterEmployeeType").getAsString());
                    maptoSend.put("afterJabatan", jsonObject.get("afterJabatan").getAsString());
                    maptoSend.put("afterDepartment", jsonObject.get("afterDepartment").getAsString());
                    break;
                default:
                    break;
                }

            } else if ((appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_APPROVED)
                    || (appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_REJECTED)) {
                //configure email parameter based on approval name   
                switch (appActivity.getApprovalDefinition().getName()) {
                case HRMConstant.VACANCY_ADVERTISEMENT:
                    List<VacancyAdvertisementDetailModel> listAdvertisementDetail = gsonDateSerializer.fromJson(
                            jsonObject.get("listAdvertisementDetail").getAsString(),
                            new TypeToken<List<VacancyAdvertisementDetailModel>>() {
                            }.getType());

                    vtm.setSubject("Pengajuan Iklan Lowongan");
                    vtm.setTemplatePath("email_vacancy_advertisement_approved_or_rejected.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("effectiveDate", jsonObject.get("effectiveDate").getAsString());
                    maptoSend.put("advertisementMediaName",
                            jsonObject.get("advertisementMediaName").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("listAdvertisementDetail", listAdvertisementDetail);
                    maptoSend.put("dateTool", new DateTool());
                    maptoSend.put("numTool", new NumberTool());
                    maptoSend.put("locale", new Locale(locale));
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.EMP_CORRECTION_ATTENDANCE:
                    List<WtEmpCorrectionAttendanceDetail> listCorrectionAttendance = gsonDateSerializer
                            .fromJson(jsonObject.get("listCorrectionAttendance").getAsString(),
                                    new TypeToken<List<WtEmpCorrectionAttendanceDetail>>() {
                                    }.getType());

                    vtm.setSubject("Pengajuan Koreksi Kehadiran");
                    vtm.setTemplatePath("email_correction_attendance_approved_or_rejected.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("listCorrectionAttendance", listCorrectionAttendance);
                    maptoSend.put("dateTool", new DateTool());
                    maptoSend.put("locale", new Locale(locale));
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.BUSINESS_TRAVEL:
                    vtm.setSubject("Permohonan Perjalanan Dinas");
                    vtm.setTemplatePath("email_travel_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("businessTravelNo", jsonObject.get("businessTravelNo").getAsString());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("destination", jsonObject.get("destination").getAsString());
                    maptoSend.put("start", jsonObject.get("startDate").getAsString());
                    maptoSend.put("end", jsonObject.get("endDate").getAsString());
                    maptoSend.put("description", jsonObject.get("description").getAsString());
                    maptoSend.put("totalAmount", jsonObject.get("totalAmount").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.REIMBURSEMENT:
                    vtm.setSubject("Permohonan Pergantian Biaya");
                    vtm.setTemplatePath("email_reimbursment_approved_or_rejected.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("reimbursementType", jsonObject.get("reimbursementType").getAsString());
                    maptoSend.put("applicationDate", jsonObject.get("applicationDate").getAsString());
                    maptoSend.put("nominal", jsonObject.get("nominal").getAsString());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.REIMBURSEMENT_DISBURSEMENT:
                    vtm.setSubject("Permohonan Pencairan Pergantian Biaya");
                    vtm.setTemplatePath("email_rmbs_disbursement_approved_or_rejected.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.LOAN:
                    vtm.setSubject("Permohonan Pinjaman Lunak");
                    vtm.setTemplatePath("email_loan_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("loanSchemaName", jsonObject.get("loanSchemaName").getAsString());
                    maptoSend.put("nominalPrincipal", jsonObject.get("nominalPrincipal").getAsString());
                    maptoSend.put("interestRate", jsonObject.get("interestRate").getAsString());
                    maptoSend.put("nominalInstallment", jsonObject.get("nominalInstallment").getAsString());
                    maptoSend.put("interestInstallment", jsonObject.get("interestInstallment").getAsString());
                    maptoSend.put("totalNominalInstallment",
                            jsonObject.get("totalNominalInstallment").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.SHIFT_SCHEDULE:
                    vtm.setSubject("Permohonan Perubahan Jadwal Kerja Karyawan");
                    vtm.setTemplatePath("email_shift_schedule_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.LEAVE:
                    vtm.setSubject("Permohonan Cuti");
                    vtm.setTemplatePath("email_leave_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("leaveName", jsonObject.get("leaveName").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("fillingDate", jsonObject.get("fillingDate").getAsString());
                    maptoSend.put("materialJobsAbandoned",
                            jsonObject.get("materialJobsAbandoned").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.LEAVE_CANCELLATION:
                    vtm.setSubject("Permohonan Pembatalan Cuti");
                    vtm.setTemplatePath("email_leave_cancellation_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("leaveName", jsonObject.get("leaveName").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("fillingDate", jsonObject.get("fillingDate").getAsString());
                    maptoSend.put("materialJobsAbandoned",
                            jsonObject.get("materialJobsAbandoned").getAsString());
                    maptoSend.put("cancellationDate", jsonObject.get("cancellationDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.OVERTIME:
                    vtm.setSubject("Permohonan Lembur");
                    vtm.setTemplatePath("email_overtime_approved_or_rejected_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("overTimeName", jsonObject.get("overTimeName").getAsString());
                    maptoSend.put("hour", jsonObject.get("hour").getAsString());
                    maptoSend.put("minute", jsonObject.get("minute").getAsString());
                    maptoSend.put("overTimeDate", jsonObject.get("overTimeDate").getAsString());
                    maptoSend.put("implementationNumber", jsonObject.get("implementationNumber").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.ANNOUNCEMENT:
                    TypeToken<List<String>> token = new TypeToken<List<String>>() {
                    };
                    List<String> dataGolonganJabatan = gson.fromJson(jsonObject.get("listGolonganJabatan"),
                            token.getType());
                    List<String> dataUnitKerja = gson.fromJson(jsonObject.get("listUnitKerja"),
                            token.getType());
                    List<String> dataEmployeeType = gson.fromJson(jsonObject.get("listEmployeeType"),
                            token.getType());

                    vtm.setSubject("Pengajuan Pengumuman");
                    vtm.setTemplatePath("email_announcement_approved_or_rejected_approval.vm");
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    maptoSend.put("subjek", jsonObject.get("subjek").getAsString());
                    maptoSend.put("content", jsonObject.get("content").getAsString());
                    maptoSend.put("company", jsonObject.get("company").getAsString());
                    maptoSend.put("listEmployeeType", dataEmployeeType);
                    maptoSend.put("listUnitKerja", dataUnitKerja);
                    maptoSend.put("listGolonganJabatan", dataGolonganJabatan);
                    break;
                case HRMConstant.PERMIT:
                    vtm.setSubject("Permohonan Izin");
                    vtm.setTemplatePath("email_permit_approved_and_rejected_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("permitClassification", jsonObject.get("permitClassification").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;
                case HRMConstant.RECRUITMENT_REQUEST:
                    vtm.setSubject("PERSETUJUAN PERMINTAAN TENAGA KERJA");
                    vtm.setTemplatePath("email_recruitment_request_approved_or_reject_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("periodeStart", jsonObject.get("periodeStart").getAsString());
                    maptoSend.put("periodeEnd", jsonObject.get("periodeEnd").getAsString());
                    maptoSend.put("jabatan", jsonObject.get("jabatan").getAsString());
                    maptoSend.put("mppName", jsonObject.get("mppName").getAsString());
                    maptoSend.put("salaryMin", jsonObject.get("salaryMin").getAsString());
                    maptoSend.put("salaryMax", jsonObject.get("salaryMax").getAsString());
                    maptoSend.put("candidateCountRequest",
                            jsonObject.get("candidateCountRequest").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;
                case HRMConstant.RECRUIT_MPP_APPLY:
                    TypeToken<List<String>> tokens = new TypeToken<List<String>>() {
                    };
                    List<String> listNamaJabatan = gson.fromJson(jsonObject.get("listNamaJabatan"),
                            tokens.getType());

                    vtm.setSubject("PERSETUJUAN RENCANA KETENAGAKERJAAN");
                    vtm.setTemplatePath("email_mpp_apply_approved_or_rejected_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("recruitMppApplyName", jsonObject.get("recruitMppApplyName").getAsString());
                    maptoSend.put("applyDate", jsonObject.get("applyDate").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("listNamaJabatan", listNamaJabatan);
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.EMPLOYEE_CAREER_TRANSITION:
                    vtm.setSubject("Pengajuan Transisi Karir");
                    if (appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_APPROVED) {
                        vtm.setTemplatePath("email_career_transition_approved.vm");
                        maptoSend.put("employeeName", requesterUser.getEmpData().getBioData().getFullName());
                        maptoSend.put("effectiveDate", jsonObject.get("effectiveDate").getAsString());
                        maptoSend.put("beforeNik", jsonObject.get("beforeNik").getAsString());
                        maptoSend.put("beforeJoinDate", jsonObject.get("beforeJoinDate").getAsString());
                        maptoSend.put("beforeEmployeeType", jsonObject.get("beforeEmployeeType").getAsString());
                        maptoSend.put("beforeJabatan", jsonObject.get("beforeJabatan").getAsString());
                        maptoSend.put("beforeDepartment", jsonObject.get("beforeDepartment").getAsString());
                        maptoSend.put("afterNik", jsonObject.get("afterNik").getAsString());
                        maptoSend.put("afterJoinDate", jsonObject.get("afterJoinDate").getAsString());
                        maptoSend.put("afterEmployeeType", jsonObject.get("afterEmployeeType").getAsString());
                        maptoSend.put("afterJabatan", jsonObject.get("afterJabatan").getAsString());
                        maptoSend.put("afterDepartment", jsonObject.get("afterDepartment").getAsString());
                    } else {
                        vtm.setTemplatePath("email_career_transition_rejected.vm");
                        maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                        maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                        maptoSend.put("beforeNik", jsonObject.get("beforeNik").getAsString());
                        maptoSend.put("beforeJoinDate", jsonObject.get("beforeJoinDate").getAsString());
                        maptoSend.put("beforeEmployeeType", jsonObject.get("beforeEmployeeType").getAsString());
                        maptoSend.put("beforeJabatan", jsonObject.get("beforeJabatan").getAsString());
                        maptoSend.put("beforeDepartment", jsonObject.get("beforeDepartment").getAsString());
                        maptoSend.put("afterNik", jsonObject.get("afterNik").getAsString());
                        maptoSend.put("afterJoinDate", jsonObject.get("afterJoinDate").getAsString());
                        maptoSend.put("afterEmployeeType", jsonObject.get("afterEmployeeType").getAsString());
                        maptoSend.put("afterJabatan", jsonObject.get("afterJabatan").getAsString());
                        maptoSend.put("afterDepartment", jsonObject.get("afterDepartment").getAsString());
                        maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    }

                    break;
                default:
                    break;
                }

            } else if ((appActivity.getApprovalStatus() == HRMConstant.APPROVAL_STATUS_CANCELLED)) {
                //configure email parameter based on approval name   
                switch (appActivity.getApprovalDefinition().getName()) {
                case HRMConstant.BUSINESS_TRAVEL:
                    vtm.setSubject("Permohonan Perjalanan Dinas");
                    vtm.setTemplatePath("email_travel_cancelled_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("businessTravelNo", jsonObject.get("businessTravelNo").getAsString());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("destination", jsonObject.get("destination").getAsString());
                    maptoSend.put("start", jsonObject.get("startDate").getAsString());
                    maptoSend.put("end", jsonObject.get("endDate").getAsString());
                    maptoSend.put("description", jsonObject.get("description").getAsString());
                    maptoSend.put("totalAmount", jsonObject.get("totalAmount").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.REIMBURSEMENT:
                    vtm.setSubject("Permohonan Pergantian Biaya");
                    vtm.setTemplatePath("email_reimbursment_cancelled.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("reimbursementType", jsonObject.get("reimbursementType").getAsString());
                    maptoSend.put("applicationDate", jsonObject.get("applicationDate").getAsString());
                    maptoSend.put("nominal", jsonObject.get("nominal").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.LOAN:
                    vtm.setSubject("Permohonan Pinjaman Lunak");
                    vtm.setTemplatePath("email_loan_cancelled_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("loanSchemaName", jsonObject.get("loanSchemaName").getAsString());
                    maptoSend.put("nominalPrincipal", jsonObject.get("nominalPrincipal").getAsString());
                    maptoSend.put("interestRate", jsonObject.get("interestRate").getAsString());
                    maptoSend.put("nominalInstallment", jsonObject.get("nominalInstallment").getAsString());
                    maptoSend.put("interestInstallment", jsonObject.get("interestInstallment").getAsString());
                    maptoSend.put("totalNominalInstallment",
                            jsonObject.get("totalNominalInstallment").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.SHIFT_SCHEDULE:
                    vtm.setSubject("Permohonan Perubahan Jadwal Kerja Karyawan");
                    vtm.setTemplatePath("email_shift_schedule_cancelled_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                case HRMConstant.LEAVE:
                    vtm.setSubject("Permohonan Cuti");
                    vtm.setTemplatePath("email_leave_cancelled_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("leaveName", jsonObject.get("leaveName").getAsString());
                    maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
                    maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
                    maptoSend.put("fillingDate", jsonObject.get("fillingDate").getAsString());
                    maptoSend.put("materialJobsAbandoned",
                            jsonObject.get("materialJobsAbandoned").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;
                case HRMConstant.OVERTIME:
                    vtm.setSubject("Permohonan Lembur");
                    vtm.setTemplatePath("email_overtime_cancelled_approval.vm");
                    maptoSend.put("approverName", approverUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("requesterName", requesterUser.getEmpData().getBioData().getFullName());
                    maptoSend.put("nik", requesterUser.getEmpData().getNik());
                    maptoSend.put("proposeDate", jsonObject.get("proposeDate").getAsString());
                    maptoSend.put("overTimeName", jsonObject.get("overTimeName").getAsString());
                    maptoSend.put("hour", jsonObject.get("hour").getAsString());
                    maptoSend.put("minute", jsonObject.get("minute").getAsString());
                    maptoSend.put("overTimeDate", jsonObject.get("overTimeDate").getAsString());
                    maptoSend.put("implementationNumber", jsonObject.get("implementationNumber").getAsString());
                    maptoSend.put("statusDesc", getStatusDesc(appActivity.getApprovalStatus(), locale));
                    break;

                default:
                    break;
                }
            }

            if (jsonObject.get("urlLinkToApprove").getAsString() != null) {
                String urlLinkToApprove = serverName + "" + jsonObject.get("urlLinkToApprove").getAsString();
                maptoSend.put("urlLinkToApprove", urlLinkToApprove);
            } else {
                maptoSend.put("urlLinkToApprove", applicationUrl);
            }

            maptoSend.put("ownerAdministrator", ownerAdministrator);
            maptoSend.put("ownerCompany", ownerCompany);
            maptoSend.put("applicationUrl", applicationUrl);
            maptoSend.put("applicationName", applicationName);
            velocityTemplateSender.sendMail(vtm, maptoSend);

            //update approval activity, set notification true
            if (appActivity.getNotificationSend() == false) {
                appActivity.setNotificationSend(true);
                this.approvalActivityDao.update(appActivity);
            }
        }
    } catch (Exception ex) {
        LOGGER.error("Error", ex);
    }
}