@SuppressWarnings("unchecked")
public Map getFilteredData(final String populationJson,final String benchmarkJson,final String topFilterJson,final int clientId,final String applicationFilePath,final String sessionId,final String userId,final String moduleType) {
logger.debug("Entered into getFilteredData");
Object object = hibernateTemplate
.execute(new HibernateCallback<Object>() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List userRoleList = new ArrayList();
Map populationMap = new HashMap();
Map benchmarkMap = new HashMap();
Map topFilterMap = new HashMap();
Map resultantMap = new HashMap();
try {
Map tempResultantMap = new HashMap();
//Getting all filter data from application cache
Map<String,String>masterFilterMappings = new HashMap<String,String>();
Map <String,String> filterLabelColumnMappings = new HashMap<String,String>();
Map topFilterMappings = (Map<String,String>) LoadApplicationCacheService.applicationCacheObject.get("topFilterMappings");
if(moduleType.equalsIgnoreCase("SALE")){
masterFilterMappings = (Map<String,String>) LoadApplicationCacheService.applicationCacheObject.get("masterFilterMappings");
filterLabelColumnMappings = (Map<String,String>) LoadApplicationCacheService.applicationCacheObject.get("filterLabelColumnMappings");
}else{
masterFilterMappings = (Map<String,String>) LoadApplicationCacheService.applicationCacheObject.get("masterFilterMappingsRent");
filterLabelColumnMappings = (Map<String,String>) LoadApplicationCacheService.applicationCacheObject.get("filterLabelColumnMappingsRent");
}
JSONObject jObject = new JSONObject(populationJson);
List tempList = null;
String tempResultantString = "";
JSONObject topFilterObject = new JSONObject(topFilterJson);
Iterator<String> keys = topFilterObject.keys();
String deriverTopFilterJson = "{";
int competitorFlag = 0;
System.out.println("object length"+topFilterObject.length());
//Extracting top filter values
while(keys.hasNext()){
String key = keys.next();
if(key.equalsIgnoreCase("population-existingProspects")||key.equalsIgnoreCase("population-CompeexistingProspects")){
deriverTopFilterJson += "\"type\" :\""+topFilterObject.getString(key)+"\",";
}else if(key.equalsIgnoreCase("population-DateParam")||key.equalsIgnoreCase("population-CompeVisitDate")){
if(key.equalsIgnoreCase("population-CompeVisitDate")){
competitorFlag = 1;
}
deriverTopFilterJson +="\"dateColumn\" : \""+topFilterMappings.get(topFilterObject.getString(key))+"\",";
/*if(topFilterObject.getString(key).equalsIgnoreCase("Prequalification Date")){
deriverTopFilterJson +="\"dateColumn\" : \"PreQualDate\",";
}else{
deriverTopFilterJson +="\"dateColumn\" : \""+topFilterObject.getString(key).replaceAll(" ", "")+"\",";
}*/
}else if(key.equalsIgnoreCase("population-date")||key.equalsIgnoreCase("population-competitorsdate")){
deriverTopFilterJson +="\"startDate\" : \""+parseDate(topFilterObject.getString(key).split("-")[0].trim())+"\",\"endDate\" : \""+parseDate(topFilterObject.getString(key).split("-")[1].trim())+"\",";
}else if(key.equalsIgnoreCase("population-MarketHouseholdType")){
deriverTopFilterJson += "\"type\" :\""+topFilterObject.getString(key)+"\",";
}
}
deriverTopFilterJson = deriverTopFilterJson.substring(0, deriverTopFilterJson.length()-1);
deriverTopFilterJson += "}";
if(jObject.length() > 0){
tempResultantMap = getDataFromDatabase(jObject,masterFilterMappings,filterLabelColumnMappings,clientId,deriverTopFilterJson,"population",applicationFilePath,sessionId,userId,competitorFlag,moduleType);
tempList = (List) tempResultantMap.get("communityList"); //getting community info
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"community",moduleType) ;
resultantMap.put("populationCount",tempResultantMap.get("nCount"));
resultantMap.put("selectedPopulationCommunitiesList", tempList);
}
tempList = (List) tempResultantMap.get("neighbourhoodList"); //getting neighborhood info
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"neighbourhood",moduleType);
//resultantMap.put("populationCount", tempList.size());
resultantMap.put("populationCount", tempResultantMap.get("nCount"));
resultantMap.put("selectedPopulationNeighbourhoodList", tempList);
}
tempList = (List) tempResultantMap.get("marketList");
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"market",moduleType);
//resultantMap.put("populationCount", tempList.size());
resultantMap.put("populationCount", tempResultantMap.get("nCount"));
}
resultantMap.put("populationJson", tempResultantString); // JSON which is used for populating population Map
resultantMap.put("populationMiles", tempResultantMap.get("milesInfo")); // Info to draw miles cirle
}
//For benchmark
jObject = new JSONObject(benchmarkJson);
keys = topFilterObject.keys();
deriverTopFilterJson = "{";
competitorFlag = 0;
// Extracting top filter info for benchmark
while(keys.hasNext()){
String key = keys.next();
if(key.equalsIgnoreCase("benchmark-existingProspects")||key.equalsIgnoreCase("benchMark-CompeexistingProspects")){
deriverTopFilterJson += "\"type\" :\""+topFilterObject.getString(key)+"\",";
}else if(key.equalsIgnoreCase("benchmark-DateParam")||key.equalsIgnoreCase("benchmark-visitDateCompe")){
if(key.equalsIgnoreCase("benchmark-visitDateCompe")){
competitorFlag = 1;
}
/*if(topFilterObject.getString(key).equalsIgnoreCase("Prequalification Date")){
deriverTopFilterJson +="\"dateColumn\" : \"PreQualDate\",";
}else{
deriverTopFilterJson +="\"dateColumn\" : \""+topFilterObject.getString(key).replaceAll(" ", "")+"\",";
}*/
deriverTopFilterJson +="\"dateColumn\" : \""+topFilterMappings.get(topFilterObject.getString(key))+"\",";
}else if(key.equalsIgnoreCase("benchmark-date")||key.equalsIgnoreCase("benchmark-competitorsdate")){
deriverTopFilterJson +="\"startDate\" : \""+parseDate(topFilterObject.getString(key).split("-")[0])+"\",\"endDate\" : \""+parseDate(topFilterObject.getString(key).split("-")[1])+"\",";
}else if(key.equalsIgnoreCase("benchmark-markethouseholdtype")){
deriverTopFilterJson += "\"type\" :\""+topFilterObject.getString(key)+"\",";
}
}
deriverTopFilterJson = deriverTopFilterJson.substring(0, deriverTopFilterJson.length()-1);
deriverTopFilterJson += "}";
if(jObject.length() > 0){
tempList = null;
tempResultantString = "";
tempResultantMap = getDataFromDatabase(jObject,masterFilterMappings,filterLabelColumnMappings,clientId,deriverTopFilterJson,"benchmark",applicationFilePath,sessionId,userId,competitorFlag,moduleType);
tempList = (List) tempResultantMap.get("communityList");
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"community",moduleType) ;
resultantMap.put("benchmarkCount", tempResultantMap.get("nCount")); // getting population count
resultantMap.put("selectedBenchmarkCommunitiesList", tempList);
}
tempList = (List) tempResultantMap.get("neighbourhoodList");
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"neighbourhood",moduleType);
//resultantMap.put("benchmarkCount", tempList.size());
resultantMap.put("benchmarkCount", tempResultantMap.get("nCount"));// getting neighborhood count
resultantMap.put("selectedBenchmarkNeighbourhoodList", tempList);
//check
}
tempList = (List) tempResultantMap.get("marketList");
if(!ApplicationUtil.isEmptyOrNull(tempList)){
tempResultantString +=convertToJson(tempList,"market",moduleType);
//resultantMap.put("benchmarkCount", tempList.size());
resultantMap.put("benchmarkCount", tempResultantMap.get("nCount"));// getting market population count
//check
}
resultantMap.put("benchmarkJson", tempResultantString);
resultantMap.put("benchmarkMiles", tempResultantMap.get("milesInfo"));
}
session.close();
} catch (HibernateException he) {
logger.error("Exception Occured :" + he
+ " at Line no :"
+ he.getStackTrace()[0].getLineNumber()
+ " in File: "
+ he.getStackTrace()[0].getFileName());
throw he;
} /*catch (ApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
return resultantMap;
}
});
return (Map)object;
}
Too large function
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.