Пример #1
0
 @Override
 public void setCustomData(CrmAccount crmAccount, CrmAccountCustomData crmAccountCustomData) {
   crmAccount.setCrmAccountCustomDataobj(crmAccountCustomData);
   save(crmAccount);
 }
Пример #2
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);
  }