List of usage examples for java.util HashMap clear
public void clear()
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
public JSONObject getCamapignWidgetReportsLink(HttpServletRequest request) throws ServiceException { List ll = null;/*from w ww . j a va 2 s . c om*/ List ll1 = null; JSONObject jobj = new JSONObject(); JSONArray jarr = new JSONArray(); int dl = 0; int dl1 = 0; boolean isExists = false; KwlReturnObject result = null; try { String companyid = sessionHandlerImpl.getCompanyid(request); String userid = sessionHandlerImpl.getUserid(request); StringBuffer usersList = crmManagerDAOObj.recursiveUsers(userid); HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("filter_names", Arrays.asList("campaignid.company.companyID", "INcampaignid.usersByUserid.userID", "campaignid.deleteflag"));// requestParams.put("filter_values", Arrays.asList(companyid, usersList, 0)); requestParams.put("select", "select emailmarketingid.name, campaignid.campaignname, sum(viewed) ,count(*),emailmarketingid.id"); requestParams.put("order_by", Arrays.asList("sum(viewed)")); requestParams.put("order_type", Arrays.asList("desc")); requestParams.put("start", 0); requestParams.put("limit", 5); requestParams.put("allflag", false); requestParams.put("group_by", Arrays.asList("emailmarketingid")); result = crmCampaignDAOObj.getCampaignLog(requestParams); ll = result.getEntityList(); dl = result.getRecordTotalCount(); Iterator ite = ll.iterator(); while (ite.hasNext()) { Object row[] = (Object[]) ite.next(); String obj = (String) row[0]; String obj2 = (String) row[1]; Long obj3 = row[2] != null ? Long.valueOf(row[2].toString()) : null; Long obj4 = row[3] != null ? Long.valueOf(row[3].toString()) : null; String marketingId = (String) row[4]; JSONObject tmpObj = new JSONObject(); tmpObj.put("marketingid", marketingId); tmpObj.put("marketingname", obj); tmpObj.put("campaignname", obj2); tmpObj.put("viewed", obj3); tmpObj.put("sentmail", obj4); jarr.put(tmpObj); } requestParams.clear(); requestParams.put("filter_names", Arrays.asList("campaignid.company.companyID", "INcampaignid.usersByUserid.userID", "campaignid.deleteflag")); requestParams.put("filter_values", Arrays.asList(companyid, usersList, 0)); requestParams.put("select", "select emailmarketingid.name, campaignid.campaignname, sum(viewed) ,count(*), emailmarketingid.id"); requestParams.put("order_by", Arrays.asList("count(*)")); requestParams.put("order_type", Arrays.asList("desc")); requestParams.put("start", 0); requestParams.put("limit", 5); requestParams.put("allflag", false); requestParams.put("group_by", Arrays.asList("emailmarketingid")); result = crmCampaignDAOObj.getCampaignLog(requestParams); ll1 = result.getEntityList(); dl1 = result.getRecordTotalCount(); Iterator ite1 = ll1.iterator(); while (ite1.hasNext()) { Object row[] = (Object[]) ite1.next(); String obj = (String) row[0]; String obj2 = (String) row[1]; Long obj3 = row[2] != null ? Long.valueOf(row[2].toString()) : null; Long obj4 = row[3] != null ? Long.valueOf(row[3].toString()) : null; String marketingId = (String) row[4]; isExists = crmEmailMarketingHandler.isAlreadyExists(jarr, marketingId); if (!isExists) { JSONObject tmpObj = new JSONObject(); tmpObj.put("marketingid", marketingId); tmpObj.put("marketingname", obj); tmpObj.put("campaignname", obj2); tmpObj.put("viewed", obj3); tmpObj.put("sentmail", obj4); jarr.put(tmpObj); } } jobj.put("success", true); jobj.put("data", jarr); jobj.put("campaignReport", true); jobj.put("totalCount", dl + dl1); } catch (Exception e) { logger.warn(e.getMessage(), e); throw ServiceException.FAILURE("crmManager.getModule", e); } return jobj; }
From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java
public JSONObject getModuleRecord(HttpServletRequest request, String moduleName, String companyid, JSONObject leadjObj, Map<String, Object> moduleFields, Map<String, Object> ColumnMappedList) throws ServiceException, JSONException, DataInvalidateException, SessionExpiredException { KwlReturnObject kmsg = null;/* ww w . j av a 2 s. c o m*/ JSONArray leadcustomFieldJArray = leadjObj.getJSONArray("customfield"); JSONArray moduleCustomfieldArray = new JSONArray(); JSONObject modulejObj = new JSONObject(); moduleFields.clear(); ColumnMappedList.clear(); try { ArrayList filter_params = new ArrayList(); ArrayList filter_names = new ArrayList(); filter_names.add("m.company.companyID"); filter_params.add(companyid); filter_names.add("m.modulefield.moduleName"); filter_params.add(moduleName); HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams = new HashMap<String, Object>(); requestParams.put("filter_names", filter_names); requestParams.put("filter_params", filter_params); kmsg = crmCommonDAOObj.getMappedHeaders(requestParams); HashMap<String, String> customFieldMap = new HashMap<String, String>(); for (int cnt = 0; cnt < leadcustomFieldJArray.length(); cnt++) { JSONObject custfindObj = leadcustomFieldJArray.getJSONObject(cnt); String fieldname = custfindObj.getString(Constants.Crm_custom_field); String fielddbname = custfindObj.getString(fieldname); customFieldMap.put(custfindObj.getString("filedid"), custfindObj.getString(fielddbname)); } List list = kmsg.getEntityList(); Iterator ite = list.iterator(); StringBuilder refNotFoundStr = new StringBuilder(); while (ite.hasNext()) { boolean refNotFoundFlag = false; LeadConversionMappings mapobj = (LeadConversionMappings) ite.next(); DefaultHeader leadDefault = mapobj.getLeadfield(); DefaultHeader moduleDefault = mapobj.getModulefield(); String newVal = ""; if (leadDefault.isCustomflag()) { String fieldId = leadDefault.getPojoheadername(); newVal = customFieldMap.get(fieldId); if (leadDefault.getXtype().equals("4")) { // normal custom combo ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("id"); filterValues.add(newVal); filterNames.add("fieldid"); filterValues.add(fieldId); filterNames.add(LeadConstants.Crm_deleteflag); filterValues.add(0); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("addMissingMaster", "false"); List li = importDao.getCustomComboID(requestParams, "value", filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0).toString(); } else { refNotFoundFlag = true; } } else if (leadDefault.getXtype().equals("7")) { String multiVal = StringUtil.getmultiSelectedColumnValue(newVal); newVal = ""; ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("INid"); filterValues.add(multiVal); filterNames.add("fieldid"); filterValues.add(fieldId); filterNames.add(LeadConstants.Crm_deleteflag); filterValues.add(0); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("addMissingMaster", "false"); List<String> li = importDao.getCustomComboID(requestParams, "value", filterNames, filterValues); StringBuilder newValbuild = new StringBuilder(); for (String s : li) { newValbuild.append(s).append(","); } if (newValbuild.length() > 0) { newVal = newValbuild.substring(0, newValbuild.length() - 1); } else { refNotFoundFlag = true; } } else if (leadDefault.getXtype().equals("8")) { // reference custom combo ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add(leadDefault.getRefFetchColumn_HbmName()); filterValues.add(newVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); requestParams.put("addMissingMaster", "false"); List<String> li = importDao.getRefModuleData(requestParams, leadDefault.getRefModule_PojoClassName(), leadDefault.getRefDataColumn_HbmName(), leadDefault.getConfigid(), filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0); } else { refNotFoundFlag = true; } } } else { newVal = leadjObj.getString(leadDefault.getRecordname()); if (!StringUtil.isNullOrEmpty(newVal)) {// get value from default column if (leadDefault.getXtype().equals("4")) { // Single-Select drop down case handled : Kuldeep Singh ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add(leadDefault.getRefFetchColumn_HbmName()); filterValues.add(newVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); List<String> li = importDao.getRefModuleData(requestParams, leadDefault.getRefModule_PojoClassName(), leadDefault.getRefDataColumn_HbmName(), leadDefault.getConfigid(), filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0); } else { refNotFoundFlag = true; } } else if (leadDefault.getXtype().equals("7")) { // Multi-Select drop down case handled : Kuldeep Singh String multiVal = StringUtil.getmultiSelectedColumnValue(newVal); newVal = ""; ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("IN" + leadDefault.getRefFetchColumn_HbmName()); filterValues.add(multiVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); List<String> li = importDao.getRefModuleData(requestParams, leadDefault.getRefModule_PojoClassName(), leadDefault.getRefDataColumn_HbmName(), leadDefault.getConfigid(), filterNames, filterValues); StringBuilder newValbuild = new StringBuilder(); for (String s : li) { newValbuild.append(s).append(","); } if (newValbuild.length() > 0) { newVal = newValbuild.substring(0, newValbuild.length() - 1); } else { refNotFoundFlag = true; } } } } if (moduleDefault.isCustomflag()) { if (!StringUtil.isNullOrEmpty(newVal)) { String moduleDefaultfieldId = moduleDefault.getPojoheadername(); if (moduleDefault.getXtype().equals("4")) {//default to normal custom column ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("value"); filterValues.add(newVal); filterNames.add("fieldid"); filterValues.add(moduleDefaultfieldId); filterNames.add(LeadConstants.Crm_deleteflag); filterValues.add(0); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("addMissingMaster", "false"); List<String> li = importDao.getCustomComboID(requestParams, "id", filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0); } else { refNotFoundFlag = true; } } else if (moduleDefault.getXtype().equals("7")) { String multiVal = StringUtil.getmultiSelectedColumnValue(newVal); newVal = ""; ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("INvalue"); filterValues.add(multiVal); filterNames.add("fieldid"); filterValues.add(moduleDefaultfieldId); filterNames.add(LeadConstants.Crm_deleteflag); filterValues.add(0); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("addMissingMaster", "false"); List<String> li = importDao.getCustomComboID(requestParams, "id", filterNames, filterValues); StringBuilder newValbuild = new StringBuilder(); for (String s : li) { newValbuild.append(s).append(","); } if (newValbuild.length() > 0) { newVal = newValbuild.substring(0, newValbuild.length() - 1); } else { refNotFoundFlag = true; } } else if (moduleDefault.getXtype().equals("8")) { // For default to reference custom combo ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add(moduleDefault.getRefDataColumn_HbmName()); filterValues.add(newVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); requestParams.put("addMissingMaster", "false"); List li = importDao.getRefModuleData(requestParams, moduleDefault.getRefModule_PojoClassName(), moduleDefault.getRefFetchColumn_HbmName(), moduleDefault.getConfigid(), filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0).toString(); } else { refNotFoundFlag = true; } } if (refNotFoundStr.length() == 0 && !refNotFoundFlag) { JSONObject tempJobj = new JSONObject(); tempJobj.put("filedid", moduleDefaultfieldId); tempJobj.put(Constants.Crm_custom_field, moduleDefault.getDefaultHeader()); tempJobj.put(moduleDefault.getDefaultHeader(), moduleDefault.getDbcolumnname()); tempJobj.put(moduleDefault.getDbcolumnname(), newVal); tempJobj.put("refcolumn_name", Constants.Custom_Column_Prefix + moduleDefault.getDbcolumnrefname()); tempJobj.put("xtype", moduleDefault.getXtype()); moduleCustomfieldArray.put(tempJobj); } else { if (refNotFoundFlag) { refNotFoundStr.append(moduleDefault.getDefaultHeader()).append(": ").append(newVal) .append(", <BR />"); } } } moduleFields.put(moduleDefault.getRecordname(), newVal); } else { if (!StringUtil.isNullOrEmpty(newVal)) { if (moduleDefault.getXtype().equals("4")) { // Single-Select drop down case handled : Kuldeep Singh ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add(moduleDefault.getRefDataColumn_HbmName()); filterValues.add(newVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); requestParams.put("addMissingMaster", "false"); List li = importDao.getRefModuleData(requestParams, moduleDefault.getRefModule_PojoClassName(), moduleDefault.getRefFetchColumn_HbmName(), moduleDefault.getConfigid(), filterNames, filterValues); if (li.size() > 0) { newVal = li.get(0).toString(); } else { refNotFoundFlag = true; } } else if (moduleDefault.getXtype().equals("7")) { // Multi-Select drop down case handled : Kuldeep Singh String multiVal = StringUtil.getmultiSelectedColumnValue(newVal); newVal = ""; ArrayList filterNames = new ArrayList<String>(); ArrayList filterValues = new ArrayList<Object>(); filterNames.add("IN" + moduleDefault.getRefDataColumn_HbmName()); filterValues.add(multiVal); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("defaultheader", moduleDefault.getDefaultHeader().trim()); requestParams.put("addMissingMaster", "false"); List<String> li = importDao.getRefModuleData(requestParams, moduleDefault.getRefModule_PojoClassName(), moduleDefault.getRefFetchColumn_HbmName(), moduleDefault.getConfigid(), filterNames, filterValues); StringBuilder newValbuild = new StringBuilder(); for (String s : li) { newValbuild.append(s).append(","); } if (newValbuild.length() > 0) { newVal = newValbuild.substring(0, newValbuild.length() - 1); } else { refNotFoundFlag = true; } } } moduleFields.put(moduleDefault.getRecordname(), newVal); if (refNotFoundStr.length() == 0 && !refNotFoundFlag) { modulejObj.put(moduleDefault.getRecordname(), newVal); } else { if (refNotFoundFlag) { refNotFoundStr.append(moduleDefault.getDefaultHeader()).append(": ").append(newVal) .append(", <BR />"); } } } ColumnMappedList.put(moduleDefault.getRecordname(), leadDefault); // mapped module record name with lead Display name } if (refNotFoundStr.length() == 0) { modulejObj.put("customfield", moduleCustomfieldArray); modulejObj.put("success", true); } else { modulejObj.put("success", false); modulejObj.put("msg", refNotFoundStr.substring(0, refNotFoundStr.length() - 1)); } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } return modulejObj; }
From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java
public ModelAndView getCampEmailMarketList(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONArray jarr = new JSONArray(); try {/*from ww w. ja va 2 s .c o m*/ HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("start", request.getParameter("start")); requestParams.put("limit", request.getParameter("limit")); requestParams.put("campid", request.getParameter("campid")); if (request.getParameter("ss") != null && !StringUtil.isNullOrEmpty(request.getParameter("ss"))) { requestParams.put("ss", request.getParameter("ss")); } int tzdiff = TimeZone.getTimeZone("GMT" + sessionHandlerImpl.getTimeZoneDifference(request)) .getOffset(System.currentTimeMillis()); ArrayList filter_names = new ArrayList(); ArrayList filter_params = new ArrayList(); filter_names.add("em.campaignid.campaignid"); filter_params.add(request.getParameter("campid")); requestParams.put("filter_names", filter_names); requestParams.put("filter_params", filter_params); DateFormat dateFormat = authHandler.getDateFormatterWithTimeZoneForExport(request); KwlReturnObject kmsg = crmEmailMarketingDAOObj.getCampEmailMarketList(requestParams); Iterator ite = kmsg.getEntityList().iterator(); while (ite.hasNext()) { EmailMarketing obj = (EmailMarketing) ite.next(); JSONObject jtemp = new JSONObject(); requestParams.clear(); requestParams.put("emailmarketingid", obj.getId()); requestParams.put("tzdiff", tzdiff); KwlReturnObject kmsg1 = crmEmailMarketingDAOObj.getCampEmailMarketCount(requestParams); KwlReturnObject kmsg2 = crmEmailMarketingDAOObj.getCampaignLog(requestParams); Iterator ite1 = kmsg2.getEntityList().iterator(); JSONArray CampaignLogData = new JSONArray(); while (ite1.hasNext()) { JSONObject tempCampaignLogData = new JSONObject(); Object[] logObj = (Object[]) ite1.next(); tempCampaignLogData.put("activitydate", logObj[0]); tempCampaignLogData.put("totalsent", logObj[1]); tempCampaignLogData.put("viewed", logObj[2]); tempCampaignLogData.put("failed", logObj[3]); tempCampaignLogData.put("usercount", logObj[4]); tempCampaignLogData.put("targetlistid", logObj[5]); tempCampaignLogData.put("targetlistname", logObj[6]); CampaignLogData.put(tempCampaignLogData); } ArrayList filter_names1 = new ArrayList(); ArrayList filter_params1 = new ArrayList(); filter_names1.add("emailmarketingid.id"); filter_params1.add(obj.getId()); requestParams.put("filter_values", filter_params1); requestParams.put("filter_names", filter_names1); KwlReturnObject kmsgforScedule = crmEmailMarketingDAOObj .getFutureScheduleEmailMarketingById(requestParams); List<scheduledmarketing> scheduledmarketingList = kmsgforScedule.getEntityList(); JSONObject CaseSheduleLog = new JSONObject(); if (scheduledmarketingList != null && !scheduledmarketingList.isEmpty()) { for (scheduledmarketing scheduleObj : scheduledmarketingList) { JSONObject CaseShedule = new JSONObject(); String starttime = scheduleObj.getScheduledtime(); Long startdate = scheduleObj.getScheduledDate(); CaseShedule.put("Date", startdate); CaseShedule.put("Time", starttime); CaseShedule.put("id", scheduleObj.getId()); CaseSheduleLog.append("SMarketingData", CaseShedule); } } String subject = obj.getTemplateid().getSubject(); if (!StringUtil.isNullOrEmpty(obj.getSubject())) { subject = obj.getSubject(); } jtemp.put("targetcount", kmsg1.getRecordTotalCount()); jtemp.put("fromaddress", obj.getFromaddress()); jtemp.put("captureLead", obj.isCaptureLead()); jtemp.put("fromname", obj.getFromname()); jtemp.put("id", obj.getId()); jtemp.put("name", obj.getName()); jtemp.put("templatename", obj.getTemplateid().getName()); jtemp.put("templateid", obj.getTemplateid().getTemplateid()); jtemp.put("templatedescription", obj.getTemplateid().getDescription()); jtemp.put("templatesubject", obj.getTemplateid().getSubject()); jtemp.put("marketingsubject", subject); jtemp.put("replymail", obj.getReplytoaddress()); jtemp.put("unsub", obj.getUnsubscribelink()); jtemp.put("fwdfriend", obj.getFwdfriendlink()); jtemp.put("archive", obj.getArchivelink()); jtemp.put("updatelink", obj.getUpdateprofilelink()); jtemp.put("createdon", (obj.getCreatedOn() != null ? obj.getCreatedOn() : "")); jtemp.put("campaignlog", CampaignLogData); jtemp.put("SMarketing", CaseSheduleLog); jtemp.put("lastrunstatus", obj.getLastRunStatus()); jarr.put(jtemp); } jobj.put("totalCount", kmsg.getRecordTotalCount()); jobj.put("data", jarr); } catch (SessionExpiredException e) { logger.warn(e.getMessage(), e); } catch (ServiceException e) { logger.warn(e.getMessage(), e); } catch (JSONException e) { logger.warn(e.getMessage(), e); } return new ModelAndView("jsonView", "model", jobj.toString()); }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
private Installment getSingleUserInstallments(String id) { String hiElement = ""; double hiVal = 0, tmpd1, tmpd2; int eff;//from ww w.ja va 2 s . c o m SqlRowSet srs1 = db.getJdbc().queryForRowSet( "select [zone],type,draw,active from installment,info_sector where id='" + id + "' and name=type"), srs2, srs3; HashMap<String, Double> elementsRatio = new HashMap<String, Double>(), elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>(); Installment installment = null; boolean pass = false; if (srs1.next()) { hiElement = ""; hiVal = 0; elementsRatio.clear(); elements.clear(); elementsCalc.clear(); pass = true; srs2 = db.getJdbc() .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("equipment_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='" + id + "' and desc_equipment.equipment='" + srs2.getString("equipment_type") + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id"); srs3.next(); elements.put(srs2.getString("equipment_type"), srs3.getDouble(1)); } srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("employee_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='" + id + "' and desc_employee.employee='" + srs2.getString("employee_type") + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id"); srs3.next(); elements.put(srs2.getString("employee_type"), srs3.getDouble(1)); } //calculating: while (true) { for (String element : elementsRatio.keySet()) { if (element.equals(hiElement)) { elementsCalc.put(element, elements.get(element)); } else { elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement)) / elementsRatio.get(hiElement)); } } for (String element : elements.keySet()) { if (elements.get(element) < elementsCalc.get(element)) { pass = false; hiElement = element; hiVal = elements.get(element); break; } else { pass = true; } } if (pass) { eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue(); if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) { hiVal = (elementsRatio.get(hiElement) * (eff + 1)); if (hiVal > 0) tmpd1 = new BigDecimal(Double.valueOf( elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1)))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff + 1; } else { hiVal = (elementsRatio.get(hiElement) * eff); if (hiVal > 0) tmpd1 = new BigDecimal(Double .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff; } installment = new Installment(id, srs1.getString("type"), srs1.getString("zone"), tmpd1, tmpd2, srs1.getString("draw"), srs1.getBoolean("active")); break; } } } hiElement = null; srs1 = null; srs2 = null; srs3 = null; elements = null; elementsCalc = null; elementsRatio = null; gc(); return installment; }
From source file:org.waarp.openr66.database.data.DbHostConfiguration.java
/** * update Alias with possible purge and new or added content, and updating in memory information * /*from www . j av a 2 s . c o m*/ * @param config * @param newalias * @param purged * @return True if updated */ public boolean updateAlias(Configuration config, String newalias, boolean purged) { HashMap<String, HashSet<String>> map = new HashMap<String, HashSet<String>>(); if (!updateMap(newalias, XML_ALIASES + "/" + XML_ALIAS, XML_REALID, XML_ALIASID, " |\\|", map)) { return false; } if (purged) { config.reverseAliases.clear(); config.aliases.clear(); } else { String alias = getAliases(); if (!updateMap(alias, XML_ALIASES + "/" + XML_ALIAS, XML_REALID, XML_ALIASID, " |\\|", map)) { return false; } } if ((newalias != null && !newalias.isEmpty()) || purged) { Document document = DocumentHelper.createDocument(DocumentHelper.createElement(XML_ALIASES)); Element root = document.getRootElement(); for (Entry<String, HashSet<String>> entry : map.entrySet()) { Element elt = root.addElement(XML_ALIAS); elt.addElement(XML_REALID).setText(entry.getKey()); String cumul = null; String[] oldAlias = config.reverseAliases.get(entry.getKey()); int size = oldAlias == null ? 0 : oldAlias.length; String[] alias = new String[entry.getValue().size() + size]; int i = 0; for (; i < size; i++) { alias[i] = oldAlias[i]; } for (String namealias : entry.getValue()) { config.aliases.put(namealias, entry.getKey()); if (cumul == null) { cumul = namealias; } else { cumul += " " + namealias; } alias[i] = namealias; i++; } elt.addElement(XML_ALIASID).setText(cumul); config.reverseAliases.put(entry.getKey(), alias); } setAliases(root.asXML()); try { update(); } catch (WaarpDatabaseException e) { document.clearContent(); document = null; return false; } document.clearContent(); document = null; } else { for (Entry<String, HashSet<String>> entry : map.entrySet()) { String[] oldAlias = config.reverseAliases.get(entry.getKey()); int size = oldAlias == null ? 0 : oldAlias.length; String[] alias = new String[entry.getValue().size() + size]; int i = 0; for (; i < size; i++) { alias[i] = oldAlias[i]; } for (String namealias : entry.getValue()) { config.aliases.put(namealias, entry.getKey()); alias[i] = namealias; i++; } config.reverseAliases.put(entry.getKey(), alias); } } map.clear(); map = null; return true; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
/** * Getting all user's installments, regardless of its type (or sector, in specifically).. * @param user/*from w w w.ja v a2 s . co m*/ * @return list of installment in ArrayList<Installment> */ private ArrayList<Installment> getUserInstallments(String user) { String hiElement = ""; double hiVal = 0, tmpd1, tmpd2; int eff; SqlRowSet srs1 = db.getJdbc() .queryForRowSet("select id,[zone],type,draw,active from installment,info_sector where [user]='" + user + "' and [zone]=(select [zone] from businessgame.dbo.[user] where name='" + user + "') and name=type"), srs2, srs3; HashMap<String, Double> elementsRatio = new HashMap<String, Double>(), elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>(); ArrayList<Installment> installments = new ArrayList<Installment>(); boolean pass = false; while (srs1.next()) { hiElement = ""; hiVal = 0; elementsRatio.clear(); elements.clear(); elementsCalc.clear(); pass = true; srs2 = db.getJdbc() .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("equipment_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='" + srs1.getString("id") + "' and desc_equipment.equipment='" + srs2.getString("equipment_type") + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id"); srs3.next(); elements.put(srs2.getString("equipment_type"), srs3.getDouble(1)); } srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("employee_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='" + srs1.getString("id") + "' and desc_employee.employee='" + srs2.getString("employee_type") + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id"); srs3.next(); elements.put(srs2.getString("employee_type"), srs3.getDouble(1)); } //calculating: while (true) { for (String element : elementsRatio.keySet()) { if (element.equals(hiElement)) { elementsCalc.put(element, elements.get(element)); } else { elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement)) / elementsRatio.get(hiElement)); } } for (String element : elements.keySet()) { if (elements.get(element) < elementsCalc.get(element)) { pass = false; hiElement = element; hiVal = elements.get(element); break; } else { pass = true; } } if (pass) { eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue(); if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) { hiVal = (elementsRatio.get(hiElement) * (eff + 1)); if (hiVal > 0) tmpd1 = new BigDecimal(Double.valueOf( elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1)))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff + 1; } else { hiVal = (elementsRatio.get(hiElement) * eff); if (hiVal > 0) tmpd1 = new BigDecimal(Double .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff; } installments.add( new Installment(srs1.getString("id"), srs1.getString("type"), srs1.getString("zone"), tmpd1, tmpd2, srs1.getString("draw"), srs1.getBoolean("active"))); break; } } } hiElement = null; srs1 = null; srs2 = null; srs3 = null; elements = null; elementsCalc = null; elementsRatio = null; gc(); return installments; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loadInstallmentOwnedByUserFromSelectedType(HttpServletRequest req) { System.out.println("Tes"); String val = "0", hiElement = ""; // val = gson.toJson(calculateInstallmentByUser(req.getParameter("user"))); double hiVal = 0, tmpd1, tmpd2; int eff;/*from w ww .j av a 2 s . c om*/ SqlRowSet srs1 = db.getJdbc() .queryForRowSet("select id,[zone],type,draw,active from installment,info_sector where [user]='" + req.getParameter("user") + "' and type='" + req.getParameter("type") + "' and [zone]=(select [zone] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "') and name=type"), srs2, srs3; HashMap<String, Double> elementsRatio = new HashMap<String, Double>(), elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>(); ArrayList<Installment> installments = new ArrayList<Installment>(); boolean pass = false; while (srs1.next()) { hiElement = ""; hiVal = 0; elementsRatio.clear(); elements.clear(); elementsCalc.clear(); pass = true; srs2 = db.getJdbc() .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("equipment_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='" + srs1.getString("id") + "' and desc_equipment.equipment='" + srs2.getString("equipment_type") + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id"); srs3.next(); elements.put(srs2.getString("equipment_type"), srs3.getDouble(1)); } srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='" + srs1.getString("type") + "'"); while (srs2.next()) { elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items")); if (hiVal < srs2.getDouble("items")) { hiElement = srs2.getString("employee_type"); hiVal = srs2.getDouble("items"); } srs3 = db.getJdbc().queryForRowSet( "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='" + srs1.getString("id") + "' and desc_employee.employee='" + srs2.getString("employee_type") + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id"); srs3.next(); elements.put(srs2.getString("employee_type"), srs3.getDouble(1)); } //calculating: while (true) { for (String element : elementsRatio.keySet()) { if (element.equals(hiElement)) { elementsCalc.put(element, elements.get(element)); } else { elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement)) / elementsRatio.get(hiElement)); } } for (String element : elements.keySet()) { if (elements.get(element) < elementsCalc.get(element)) { pass = false; hiElement = element; hiVal = elements.get(element); break; } else { pass = true; } } if (pass) { eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue(); if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) { hiVal = (elementsRatio.get(hiElement) * (eff + 1)); if (hiVal > 0) tmpd1 = new BigDecimal(Double.valueOf( elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1)))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff + 1; } else { hiVal = (elementsRatio.get(hiElement) * eff); if (hiVal > 0) tmpd1 = new BigDecimal(Double .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff))) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); else tmpd1 = 0; tmpd2 = eff; } installments.add( new Installment(srs1.getString("id"), srs1.getString("type"), srs1.getString("zone"), tmpd1, tmpd2, srs1.getString("draw"), srs1.getBoolean("active"))); break; } } } val = gson.toJson(installments); installments = null; hiElement = null; srs1 = null; srs2 = null; srs3 = null; elements = null; elementsCalc = null; elementsRatio = null; gc(); return val; }
From source file:com.wizecommerce.hecuba.HecubaCassandraManagerTestBase.java
@Test public void testReadColumnSlice() throws Exception { logger.info("Testing Hector read column slice"); HecubaClientManager<Long> cassandraManager = getHecubaClientManager(); HashMap<String, Object> row = new HashMap<String, Object>(); /*********************************************************/ /****** TEST CASSANDRA ROW CONTAINS > 100 COLUMNS ********/ /*********************************************************/ // Insert 200 columns in cassandra in a single row int noOfColumns = 200; Long key = 1234L;/*from w ww. j av a 2 s .c om*/ for (int i = 1; i <= noOfColumns; i++) { row.put("column_" + i, "value_" + i); } cassandraManager.updateRow(key, row); /** * ____________________________________________________________ | Retrieve all columns for the key (no of columns < 10000) * ------------------------------------------------------------ */ // Retrieve all columns CassandraResultSet<Long, String> result = cassandraManager.readColumnSliceAllColumns(key); // Column count should be 200 assertEquals(noOfColumns, result.getColumnNames().size()); for (String columnName : row.keySet()) { assertEquals(row.get(columnName), result.getString(columnName)); } /** * __________________________________ | Retrieve N columns for the key ---------------------------------- */ // Retrieve 120 columns result = cassandraManager.readColumnSlice(key, null, null, false, 120); // Column count should be 120 assertEquals(120, result.getColumnNames().size()); /** * _________________________________________________ | Retrieve N columns with column range specified ------------------------------------------------- */ // Columns in a range with limit as 10 result = cassandraManager.readColumnSlice(key, "column_111", "column_113", false, 10); // This range contains 3 columns, so the column count should be 3 assertEquals(3, result.getColumnNames().size()); assertEquals("value_111", result.getString("column_111")); assertEquals("value_112", result.getString("column_112")); assertEquals("value_113", result.getString("column_113")); /*********************************************************/ /****** TEST CASSANDRA ROW CONTAINS < 100 COLUMNS ********/ /*********************************************************/ /** * __________________________________________________ | Retrieve all columns for row with < 100 columns -------------------------------------------------- */ row.clear(); key = 5678L; for (int i = 1; i <= 80; i++) { // < 100 columns (80 in this example) row.put("column_" + i, "value_" + i); } cassandraManager.updateRow(key, row); result = cassandraManager.readColumnSliceAllColumns(key); // Column count should be 80 assertEquals(80, result.getColumnNames().size()); for (String columnName : row.keySet()) { assertEquals(row.get(columnName), result.getString(columnName)); } /** * __________________________________ | Retrieve N columns for the key ---------------------------------- */ // Retrieve 50 columns result = cassandraManager.readColumnSlice(key, null, null, false, 50); // Column count should be 120 assertEquals(50, result.getColumnNames().size()); /** * _________________________________________________ | Retrieve N columns with column range specified ------------------------------------------------- */ // Columns in a range with limit as 10 result = cassandraManager.readColumnSlice(key, "column_11", "column_13", false, 10); // This range contains 3 columns, so the column count should be 3 assertEquals(3, result.getColumnNames().size()); assertEquals("value_11", result.getString("column_11")); assertEquals("value_12", result.getString("column_12")); assertEquals("value_13", result.getString("column_13")); /*************************************************************/ /****** TEST CASSANDRA ROW DOES NOT EXIST (CACHE MISS) *******/ /*************************************************************/ row.clear(); key = 9999L; result = cassandraManager.readColumnSliceAllColumns(key); assertEquals(0, result.getColumnNames().size()); result = cassandraManager.readColumnSlice(key, null, null, false, 50); assertEquals(0, result.getColumnNames().size()); result = cassandraManager.readColumnSlice(key, "column_11", "column_13", false, 10); assertEquals(0, result.getColumnNames().size()); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
protected boolean Sync(String service, String scope, String params) { final Date start = new Date(); boolean hasError = false; if (params == null) params = ""; final SQLiteDatabase db = mDB.getWritableDatabase(); final ArrayList<TableInfo> notifyTableInfo = new ArrayList<TableInfo>(); final String download = String.format(contentHelper.DOWNLOAD_SERVICE_URI, service, scope, params); final String upload = String.format(contentHelper.UPLOAD_SERVICE_URI, service, scope, params); final String scopeServerBlob = String.format("%s.%s.%s", service, scope, _.serverBlob); String serverBlob = null;//from w ww. j a v a 2 s. com Cursor cur = db.query(BlobsTable.NAME, new String[] { BlobsTable.C_VALUE }, BlobsTable.C_NAME + "=?", new String[] { scopeServerBlob }, null, null, null); final String originalBlob; if (cur.moveToFirst()) { originalBlob = serverBlob = cur.getString(0); } else { originalBlob = null; } cur.close(); db.beginTransaction(); try { boolean nochanges = false; if (serverBlob != null) { nochanges = !contentHelper.hasDirtTable(db, scope); } boolean resolve = false; final Metadata meta = new Metadata(); final HashMap<String, Object> vals = new HashMap<String, Object>(); final ContentValues cv = new ContentValues(2); JsonFactory jsonFactory = new JsonFactory(); JsonToken current = null; String name = null; boolean moreChanges = false; boolean forceMoreChanges = false; do { final int requestMethod; final String serviceRequestUrl; final ContentProducer contentProducer; if (serverBlob != null) { requestMethod = HTTP_POST; if (nochanges) { serviceRequestUrl = download; } else { serviceRequestUrl = upload; forceMoreChanges = true; } contentProducer = new SyncContentProducer(jsonFactory, db, scope, serverBlob, !nochanges, notifyTableInfo, contentHelper); nochanges = true; } else { requestMethod = HTTP_GET; serviceRequestUrl = download; contentProducer = null; } if (moreChanges) { db.beginTransaction(); } Result result = executeRequest(requestMethod, serviceRequestUrl, contentProducer); if (result.getStatus() == HttpStatus.SC_OK) { final JsonParser jp = jsonFactory.createParser(result.getInputStream()); jp.nextToken(); // skip ("START_OBJECT(d) expected"); jp.nextToken(); // skip ("FIELD_NAME(d) expected"); if (jp.nextToken() != JsonToken.START_OBJECT) throw new Exception("START_OBJECT(d - object) expected"); while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); if (_.__sync.equals(name)) { current = jp.nextToken(); while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); current = jp.nextToken(); if (_.serverBlob.equals(name)) { serverBlob = jp.getText(); } else if (_.moreChangesAvailable.equals(name)) { moreChanges = jp.getBooleanValue() || forceMoreChanges; forceMoreChanges = false; } else if (_.resolveConflicts.equals(name)) { resolve = jp.getBooleanValue(); } } } else if (_.results.equals(name)) { if (jp.nextToken() != JsonToken.START_ARRAY) throw new Exception("START_ARRAY(results) expected"); while (jp.nextToken() != JsonToken.END_ARRAY) { meta.isDeleted = false; meta.tempId = null; vals.clear(); while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); current = jp.nextToken(); if (current == JsonToken.VALUE_STRING) { vals.put(name, jp.getText()); } else if (current == JsonToken.VALUE_NUMBER_INT) { vals.put(name, jp.getLongValue()); } else if (current == JsonToken.VALUE_NUMBER_FLOAT) { vals.put(name, jp.getDoubleValue()); } else if (current == JsonToken.VALUE_FALSE) { vals.put(name, 0L); } else if (current == JsonToken.VALUE_TRUE) { vals.put(name, 1L); } else if (current == JsonToken.VALUE_NULL) { vals.put(name, null); } else { if (current == JsonToken.START_OBJECT) { if (_.__metadata.equals(name)) { while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); jp.nextToken(); if (_.uri.equals(name)) { meta.uri = jp.getText(); } else if (_.type.equals(name)) { meta.type = jp.getText(); } else if (_.isDeleted.equals(name)) { meta.isDeleted = jp.getBooleanValue(); } else if (_.tempId.equals(name)) { meta.tempId = jp.getText(); } } } else if (_.__syncConflict.equals(name)) { while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); jp.nextToken(); if (_.isResolved.equals(name)) { } else if (_.conflictResolution.equals(name)) { } else if (_.conflictingChange.equals(name)) { while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); current = jp.nextToken(); if (current == JsonToken.START_OBJECT) { if (_.__metadata.equals(name)) { while (jp.nextToken() != JsonToken.END_OBJECT) { } } } } } } // resolve conf } else if (_.__syncError.equals(name)) { while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); jp.nextToken(); } } } } } TableInfo tab = contentHelper.getTableFromType(meta.type); if (meta.isDeleted) { tab.DeleteWithUri(meta.uri, db); } else { tab.SyncJSON(vals, meta, db); } if (!notifyTableInfo.contains(tab)) notifyTableInfo.add(tab); } } } jp.close(); if (!hasError) { cv.clear(); cv.put(BlobsTable.C_NAME, scopeServerBlob); cv.put(BlobsTable.C_VALUE, serverBlob); cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis()); cv.put(BlobsTable.C_STATE, 0); db.replace(BlobsTable.NAME, null, cv); db.setTransactionSuccessful(); db.endTransaction(); if (DEBUG) { Log.d(TAG, "CP-Sync: commit changes"); } final ContentResolver cr = getContext().getContentResolver(); for (TableInfo t : notifyTableInfo) { final Uri nu = contentHelper.getDirUri(t.name, false); cr.notifyChange(nu, null, false); // false - do not force sync cause we are in sync if (DEBUG) { Log.d(TAG, "CP-Sync: notifyChange table: " + t.name + ", uri: " + nu); } for (String n : t.notifyUris) { cr.notifyChange(Uri.parse(n), null, false); if (DEBUG) { Log.d(TAG, "+uri: " + n); } } } notifyTableInfo.clear(); } } else { if (DEBUG) { Log.e(TAG, "Server error in fetching remote contacts: " + result.getStatus()); } hasError = true; break; } } while (moreChanges); } catch (final ConnectTimeoutException e) { hasError = true; if (DEBUG) { Log.e(TAG, "ConnectTimeoutException", e); } } catch (final IOException e) { hasError = true; if (DEBUG) { Log.e(TAG, Log.getStackTraceString(e)); } } catch (final ParseException e) { hasError = true; if (DEBUG) { Log.e(TAG, "ParseException", e); } } catch (final Exception e) { hasError = true; if (DEBUG) { Log.e(TAG, "ParseException", e); } } if (hasError) { db.endTransaction(); ContentValues cv = new ContentValues(); cv.put(BlobsTable.C_NAME, scopeServerBlob); cv.put(BlobsTable.C_VALUE, originalBlob); cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis()); cv.put(BlobsTable.C_STATE, -1); db.replace(BlobsTable.NAME, null, cv); } /*-if (!hasError) { final ContentValues cv = new ContentValues(2); cv.put(BlobsTable.C_NAME, scopeServerBlob); cv.put(BlobsTable.C_VALUE, serverBlob); db.replace(BlobsTable.NAME, null, cv); db.setTransactionSuccessful(); } db.endTransaction(); if (!hasError) { for (String t : notifyTableInfo) { getContext().getContentResolver().notifyChange(getDirUri(t), null); } }*/ if (DEBUG) { Helpers.LogInfo(start); } return !hasError; }
From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java
public ModelAndView targetListForImport(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONArray jarr = new JSONArray(); JSONObject jobjTemp = new JSONObject(); JSONArray jarrColumns = new JSONArray(); JSONArray jarrRecords = new JSONArray(); JSONObject jMeta = new JSONObject(); try {//from w ww . j ava 2 s . c o m HashMap<String, Object> requestParams = new HashMap<String, Object>(); HashMap<String, Object> innerrequestParams = new HashMap<String, Object>(); String companyid = sessionHandlerImpl.getCompanyid(request); ArrayList filter_names = new ArrayList(); ArrayList filter_params = new ArrayList(); filter_names.add("deleted"); filter_params.add(0); filter_names.add("creator.company.companyID"); filter_params.add(companyid); filter_names.add("saveflag"); filter_params.add(1); filter_names.add("!id"); filter_params.add(request.getParameter("tlid")); if (request.getParameter("ss") != null && !StringUtil.isNullOrEmpty(request.getParameter("ss"))) { requestParams.put("ss", request.getParameter("ss")); } requestParams.put("start", StringUtil.checkForNull(request.getParameter("start"))); requestParams.put("limit", StringUtil.checkForNull(request.getParameter("limit"))); requestParams.put("filter_names", filter_names); requestParams.put("filter_params", filter_params); KwlReturnObject kmsg = crmEmailMarketingDAOObj.getTargetList(requestParams); Iterator ite = kmsg.getEntityList().iterator(); while (ite.hasNext()) { TargetList obj = (TargetList) ite.next(); JSONObject jtemp = new JSONObject(); jtemp.put("relatedid", obj.getId()); jtemp.put("name", obj.getName()); jtemp.put("targetlistDescription", obj.getDescription()); innerrequestParams.clear(); innerrequestParams.put("listID", obj.getId()); filter_names.clear(); filter_params.clear(); filter_names.add("targetlisttargets.targetlistid.id"); filter_params.add(obj.getId()); innerrequestParams.put("filter_names", filter_names); innerrequestParams.put("filter_params", filter_params); innerrequestParams.put("companyid", companyid); KwlReturnObject innerkmsg = crmEmailMarketingDAOObj.getTargetListTargets(innerrequestParams); jtemp.put("targetscount", innerkmsg.getRecordTotalCount()); jarr.put(jtemp); } jobjTemp = new JSONObject(); jobjTemp.put("header", mSource.getMessage("crm.targetlists.targetlistname", null, RequestContextUtils.getLocale(request)));//"Target List Name"); jobjTemp.put("tip", mSource.getMessage("crm.targetlists.targetlistname", null, RequestContextUtils.getLocale(request)));//"Target List Name"); jobjTemp.put("pdfwidth", 60); jobjTemp.put("dataIndex", "name"); jarrColumns.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("header", mSource.getMessage("crm.targetlists.targetlistname", null, RequestContextUtils.getLocale(request)));//"No of Targets"); jobjTemp.put("tip", mSource.getMessage("crm.targetlists.targetlistname", null, RequestContextUtils.getLocale(request)));//"No of Targets"); jobjTemp.put("pdfwidth", 60); jobjTemp.put("dataIndex", "targetscount"); jarrColumns.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("header", mSource.getMessage("crm.case.defaultheader.desc", null, RequestContextUtils.getLocale(request)));//"Description"); jobjTemp.put("tip", mSource.getMessage("crm.case.defaultheader.desc", null, RequestContextUtils.getLocale(request)));//"Description"); jobjTemp.put("pdfwidth", 60); jobjTemp.put("dataIndex", "targetlistDescription"); jarrColumns.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "targetscount"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "name"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "emailid"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "relatedto"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "company"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "targetlistDescription"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "relatedid"); jarrRecords.put(jobjTemp); jobjTemp = new JSONObject(); jobjTemp.put("name", "fname"); jarrRecords.put(jobjTemp); jobj.put("columns", jarrColumns); jMeta.put("totalProperty", "totalCount"); jMeta.put("root", "data"); jMeta.put("fields", jarrRecords); jobj.put("metaData", jMeta); jobj.put("totalCount", kmsg.getRecordTotalCount()); jobj.put("data", jarr); } catch (ServiceException e) { logger.warn(e.getMessage(), e); } catch (Exception e) { logger.warn(e.getMessage(), e); } return new ModelAndView("jsonView", "model", jobj.toString()); }