Exemplo n.º 1
0
 public void setCustomData(CrmAccount crmAcc, JSONArray cstmData) {
   StringBuffer fields = new StringBuffer("accountid,company");
   StringBuffer qmarks = new StringBuffer("?,?");
   ArrayList params = new ArrayList();
   params.add(crmAcc.getAccountid());
   params.add(crmAcc.getCompany().getCompanyID());
   boolean hasValue = false;
   try {
     for (int i = 0; i < cstmData.length(); i++) {
       JSONObject jobj = cstmData.getJSONObject(i);
       if (jobj.has(Constants.Crm_custom_field)) {
         String fieldname = jobj.getString(Constants.Crm_custom_field);
         String fielddbname = jobj.getString(fieldname);
         String fieldValue = jobj.getString(fielddbname);
         hasValue = true;
         fielddbname = fielddbname.replace("c", "C");
         Integer xtype = Integer.parseInt(jobj.getString("xtype"));
         if (!StringUtil.isNullOrEmpty(fieldValue)
             && !StringUtil.isNullOrEmpty(fieldValue.trim())
             && !fieldValue.equalsIgnoreCase(Constants.field_data_undefined)) {
           fields.append(',').append(fielddbname);
           qmarks.append(",?");
           params.add(fieldValue);
         } else {
           if (xtype == 7 || xtype == 8 || xtype == 4) {
             fields.append(',').append(fielddbname);
             qmarks.append(",?");
             params.add(null);
           } else {
             fields.append(',').append(fielddbname);
             qmarks.append(",?");
             params.add("");
           }
         }
       }
     }
   } catch (NumberFormatException e) {
     e.printStackTrace();
   } catch (JSONException e) {
     e.printStackTrace();
   }
   if (hasValue) {
     StringBuffer sql =
         new StringBuffer("insert into crmaccountcustomdata (")
             .append(fields)
             .append(")VALUES(")
             .append(qmarks)
             .append(')');
     updateJDBC(sql.toString(), params.toArray());
   }
 }
Exemplo n.º 2
0
 @Override
 public void setCustomData(CrmAccount crmAccount, CrmAccountCustomData crmAccountCustomData) {
   crmAccount.setCrmAccountCustomDataobj(crmAccountCustomData);
   save(crmAccount);
 }
Exemplo n.º 3
0
  /* (non-Javadoc)
   * @see com.krawler.spring.crm.accountModule.crmAccountDAO#editAccounts(com.krawler.utils.json.base.JSONObject)
   */
  public KwlReturnObject editAccounts(JSONObject jobj) throws ServiceException {
    List ll = new ArrayList();
    int dl = 0;
    try {
      String companyid = null;
      String userid = null;
      String id = "";
      if (jobj.has("accountid")) {
        id = jobj.getString("accountid");
      }
      CrmAccount crmAccount = (CrmAccount) get(CrmAccount.class, id);
      if (jobj.has("accountname")) {
        crmAccount.setAccountname(jobj.getString("accountname"));
      }
      if (jobj.has("accounttypeid")) {
        crmAccount.setCrmCombodataByAccounttypeid(
            (DefaultMasterItem) get(DefaultMasterItem.class, jobj.getString("accounttypeid")));
      }
      if (jobj.has("companyid")) {
        companyid = jobj.getString("companyid");
        crmAccount.setCompany((Company) get(Company.class, companyid));
      }
      if (jobj.has("description")) {
        crmAccount.setDescription(jobj.getString("description"));
      }
      if (jobj.has("website")) {
        crmAccount.setWebsite(jobj.getString("website"));
      }
      if (jobj.has("email")) {
        crmAccount.setEmail(jobj.getString("email"));
      }
      if (jobj.has("address")) {
        crmAccount.setMailstreet(jobj.getString("address"));
      }
      if (jobj.has("productid")) {
        saveAccountProducts(new String[] {id}, jobj.getString("productid").split(","));
      }
      if (jobj.has("price")) {
        crmAccount.setPrice(jobj.getString("price"));
      }
      if (jobj.has("phone")) {
        crmAccount.setPhone(jobj.getString("phone"));
      }
      if (jobj.has("revenue")) {
        crmAccount.setRevenue(jobj.getString("revenue"));
      }
      if (jobj.has("industryid")) {
        crmAccount.setCrmCombodataByIndustryid(
            (DefaultMasterItem) get(DefaultMasterItem.class, jobj.getString("industryid")));
      }
      if (jobj.has("updatedon")) {
        crmAccount.setUpdatedOn(System.currentTimeMillis());
      }
      if (jobj.has("createdon")) {
        crmAccount.setCreatedOn(jobj.getLong("createdon"));
      } else {
        crmAccount.setCreatedOn(System.currentTimeMillis());
      }
      if (jobj.has("userid")) {
        userid = jobj.getString("userid");
        crmAccount.setUsersByUpdatedbyid((User) get(User.class, userid));
        //                crmAccount.setUsersByCreatedbyid((User) hibernateTemplate.get(User.class,
        // userid));
      }
      if (jobj.has("accountownerid")) {
        setMainAccOwner(new String[] {id}, jobj.getString("accountownerid"));
        //                crmAccount.setUsersByUserid((User) hibernateTemplate.get(User.class,
        // jobj.getString("accountownerid")));
      }
      if (jobj.has("validflag")) {
        crmAccount.setValidflag(Integer.parseInt(jobj.getString("validflag")));
      }
      if (jobj.has("isarchive")) {
        crmAccount.setIsarchive(jobj.getBoolean("isarchive"));
      }
      if (jobj.has("deleteflag")) {
        crmAccount.setDeleteflag(Integer.parseInt(jobj.getString("deleteflag")));
        try {
          if (Integer.parseInt(jobj.getString("deleteflag")) == 1) {
            String query = "delete from AccountProducts where accountid.accountid=?";
            executeUpdate(query, id);
          }
        } catch (Exception te) {
          logger.warn("Products related to the account could not be deleted :", te);
        }
      }
      if (jobj.has("CrmAccountCustomDataobj")) {
        crmAccount.setCrmAccountCustomDataobj(
            (CrmAccountCustomData)
                get(CrmAccountCustomData.class, jobj.getString("CrmAccountCustomDataobj")));
      }
      if (jobj.has("leadid")) {
        crmAccount.setCrmLead((CrmLead) get(CrmLead.class, jobj.getString("leadid")));
      }
      saveOrUpdate(crmAccount);

      ll.add(crmAccount);
    } catch (JSONException e) {
      throw ServiceException.FAILURE("crmAccountDAOImpl.editAccounts : " + e.getMessage(), e);
    } catch (DataAccessException e) {
      throw ServiceException.FAILURE("crmAccountDAOImpl.editAccounts : " + e.getMessage(), e);
    } catch (Exception e) {
      throw ServiceException.FAILURE("crmAccountDAOImpl.editAccounts : " + e.getMessage(), e);
    }
    return new KwlReturnObject(true, KWLErrorMsgs.S01, "", ll, dl);
  }