Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/environment/common_test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ callRetryConfiguration=3
#avni registration Duration
avniRegistrationLimit=7


#--------------------------NHM Agent Real Time Data----------------------------
nhm.agent.real.time.data.url= http://175.101.1.83/apps/utility/alive_api.php
nhm.agent.real.time.data.cron.scheduler=0 */2 * ? * *
nhm.agent.real.time.data.cron.flag=true
2 changes: 2 additions & 0 deletions src/main/java/com/iemr/common/CommonApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.iemr.common.utils.IEMRApplBeans;

@SpringBootApplication
@EnableScheduling
public class CommonApplication extends SpringBootServletInitializer {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.iemr.common.config.quartz;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.iemr.common.service.nhm_dashboard.NHM_AgentRealTimeDataService;
@Component
public class ScheduleJobForNHMAgentRealTimeData {
@Value("${nhm.agent.real.time.data.cron.flag}")
private boolean nhmFlag;

private final Logger log = LoggerFactory.getLogger(this.getClass().getName());

@Autowired
NHM_AgentRealTimeDataService agentRealTimeDataService;
@Scheduled(cron = "${nhm.agent.real.time.data.cron.scheduler}")
public void getAllNHMAgentRealTimeData() throws IOException {
if(nhmFlag) {
log.info("Calling Scheduler for NHM_Agent_Real_Time_Data");
agentRealTimeDataService.getData();
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/iemr/common/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.iemr.common.constant;

public class Constants {

public static final String NHM_CRON_JOB = "nhmCronJob";
public static final String NHM_CRON_SCHEDULER = "nhm-cron-scheduler";
public static final String LOGGED_IN = "Loggedin";
public static final String FREE = "Free";
public static final String IN_CALL = "Incall";
public static final String AWT = "AWT";
public static final String HOLD = "Hold";
public static final String NOT_READY = "Not Ready";
public static final String AUX = "Aux";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.iemr.common.data.nhm_dashboard;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.google.gson.annotations.Expose;

import lombok.Data;

@Data
@Entity
@Table(name = "t_nhmagentrealtimedata")
public class AgentRealTimeData {
@Id
@GeneratedValue
@Expose
@Column(name = "id", insertable = false)
private Long id;

@Expose
@Column(name="CampaignName")
private String campaignName;

@Expose
@Column(name="Loggedin")
private int loggedIn;

@Expose
@Column(name="Free")
private int free;

@Expose
@Column(name="Incall")
private int inCall;
@Expose
@Column(name="AWT")
private int awt;

@Expose
@Column(name="Hold")
private int hold;

@Expose
@Column(name="NotReady")
private int notReady;

@Expose
@Column(name="Aux")
private int aux;

@Expose
@Column(name="Deleted",insertable = false, updatable = true)
private Boolean deleted;

@Expose
@Column(name = "Processed", insertable = false)
private String processed;

@Expose
@Column(name="CreatedBy")
private String createdBy;

@Expose
@Column(name="CreatedDate")
private Timestamp createdDate;

@Expose
@Column(name="ModifiedBy")
private String modifiedBy;

@Expose
@Column(name="LastModDate")
private Timestamp modifiedDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.iemr.common.data.nhm_dashboard;

import lombok.Data;

@Data
public class NHMAgentRequest {
private String campaign_name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.iemr.common.repository.nhm_dashboard;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.iemr.common.data.nhm_dashboard.AgentRealTimeData;
@Repository
public interface NHMAgentRealTimeDataRepo extends CrudRepository<AgentRealTimeData, Long>{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.iemr.common.service.nhm_dashboard;

import java.io.IOException;

public interface NHM_AgentRealTimeDataService {

String getData() throws IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.iemr.common.service.nhm_dashboard;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.iemr.common.constant.Constants;
import com.iemr.common.data.nhm_dashboard.AgentRealTimeData;
import com.iemr.common.data.nhm_dashboard.NHMAgentRequest;
import com.iemr.common.repository.nhm_dashboard.NHMAgentRealTimeDataRepo;


@Service
public class NHM_AgentRealTimeDatacServiceImpl implements NHM_AgentRealTimeDataService {
private final Logger log = LoggerFactory.getLogger(this.getClass().getName());

@Value("${nhm.agent.real.time.data.url}")
private String czUrl;
@Autowired
NHMAgentRealTimeDataRepo agentRealTimeDataRepo;

@Override
public String getData() throws IOException {
RestTemplate restTemplate = new RestTemplate();
ArrayList<AgentRealTimeData> arrayList = new ArrayList<AgentRealTimeData>();
NHMAgentRequest nhmAgentRequest = new NHMAgentRequest();
nhmAgentRequest.setCampaign_name("all");
String json = new Gson().toJson(nhmAgentRequest);
MultiValueMap<String, String> headersLogin = new LinkedMultiValueMap<String, String>();
headersLogin.add("Content-Type", "application/json");

HttpEntity<Object> request = new HttpEntity<Object>(json, headersLogin);
String resp = null;
try {
ResponseEntity<String> exchange = restTemplate.exchange(czUrl, HttpMethod.POST, request, String.class);
resp = exchange.getBody();
} catch (Exception e) {
log.error("Error While callin CZ Url : " + czUrl + " Error Message " + e.getMessage());
}
ObjectMapper mapper = new ObjectMapper();
if (null != resp && resp.startsWith("[") && resp.endsWith("]")) {
ArrayList<HashMap<String, Object>> readValue = mapper.readValue(resp, ArrayList.class);
for (HashMap<String, Object> object : readValue) {
HashMap convertValue = mapper.convertValue(object, HashMap.class);
for (String key : object.keySet()) {
AgentRealTimeData agentRealTimeData = new AgentRealTimeData();
HashMap<String, Integer> object2 = (HashMap<String, Integer>) convertValue.get(key);
agentRealTimeData.setCampaignName(key);
agentRealTimeData.setCreatedBy("default");
agentRealTimeData.setModifiedBy("default");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
String DateToStoreInDataBase = sdf.format(new Date());
Timestamp ts = Timestamp.valueOf(DateToStoreInDataBase);
agentRealTimeData.setCreatedDate(ts);
agentRealTimeData.setModifiedDate(ts);
for (String key1 : object2.keySet()) {
if (key1.equalsIgnoreCase(Constants.LOGGED_IN))
agentRealTimeData.setLoggedIn(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.FREE))
agentRealTimeData.setFree(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.IN_CALL))
agentRealTimeData.setInCall(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.AWT))
agentRealTimeData.setAwt(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.HOLD))
agentRealTimeData.setHold(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.NOT_READY))
agentRealTimeData.setNotReady(object2.get(key1));
if (key1.equalsIgnoreCase(Constants.AUX))
agentRealTimeData.setAux(object2.get(key1));
}
arrayList.add(agentRealTimeData);
}
}
}
if(null != arrayList && !ObjectUtils.isEmpty(arrayList)) {
agentRealTimeDataRepo.deleteAll();
agentRealTimeDataRepo.save(arrayList);
}
return resp;
}

}