package com.highway2urhell.service;

import com.highway2urhell.dao.MetricsTimerDao;
import com.highway2urhell.domain.MessageMetrics;
import com.highway2urhell.domain.MetricsTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;

@Named
public class MetricsTimerService {

	private static final Logger LOG = LoggerFactory
			.getLogger(MetricsTimerService.class);
	
	@Inject
	private MetricsTimerDao metricsTimerDao;


	/**
	 * List MessageMetrics filter by TimeStamp
	 *
	 */


	public void addListPerformance(List<MessageMetrics> listPerf) {
		if (listPerf != null && !listPerf.isEmpty()) {
			for (MessageMetrics msg : listPerf) {
				LOG.info(
						"add indicator Performance for pathClassMethodName {} time {} token {} and dateIncoming {}",
						msg.getPathClassMethodName(), msg.getTimeExec(),
						msg.getToken(), msg.getDateIncoming());
				createMetricsTimer(msg);
			}
		}
	}



	@Transactional
	public void createMetricsTimer(MessageMetrics mm) {
		MetricsTimer mt = new MetricsTimer();
		mt.setDateIncoming(mm.getDateIncoming());
		mt.setPathClassMethodName(mm.getPathClassMethodName());
		mt.setTimeExec(mm.getTimeExec());;
		mt.setToken(mm.getToken());
		metricsTimerDao.save(mt);
	}

}

@@ -351,16 +351,107 @@
 .Named;%0A
+import java.text.ParseException;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0A
 import j
@@ -1197,16 +1197,25 @@
 s mm) %7B%0A
+%09%09try %7B%0A%09
 %09%09Metric
@@ -1246,16 +1246,115 @@
 imer();%0A
+%09%09%09SimpleDateFormat sdf = new SimpleDateFormat(%22dd-MM-yyyy:hh-mm-ss%22);%0A%09%09%09Date date = new Date();%0A%09
 %09%09mt.set
@@ -1366,16 +1366,26 @@
 ncoming(
+sdf.parse(
 mm.getDa
@@ -1397,18 +1397,20 @@
 oming())
+)
 ;%0A
+%09
 %09%09mt.set
@@ -1457,24 +1457,25 @@
 dName());%0A%09%09
+%09
 mt.setTimeEx
@@ -1495,18 +1495,23 @@
 Exec());
+%0A%09%09%09
 ;%0A
+%09
 %09%09mt.set
@@ -1534,16 +1534,17 @@
 n());%0A%09%09
+%09
 metricsT
@@ -1561,14 +1561,92 @@
 ve(mt);%0A
+%09%09%7Dcatch (ParseException e)%7B%0A%09%09%09LOG.error(%22 Impossible save metrics %22,e);%0A%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

fix date transfer for metrics