Package com.knowgate.crm

Examples of com.knowgate.crm.DistributionList


    PreparedStatement oJobStmt;
    DBSubset  oJobsSet;
    int iJobCount;
    Properties oParams;
    DistributionList oDistribList;
    Date dtNow = new Date();
    Date dtExec;
    String sSQL;
    int iLoaded = 0;

    if (DebugFile.trace) {
       DebugFile.writeln("Begin AtomFeeder.loadAtoms([Connection], " + String.valueOf(iWorkerThreads) + ")");
       DebugFile.incIdent();
     }

    // Crea un DBSubset para recorrer los jobs pendientes de ejecución

    oJobsSet = new DBSubset(DB.k_jobs,
                            "gu_job,gu_job_group,gu_workarea,id_command,tx_parameters,id_status,dt_execution,dt_finished,dt_created,dt_modified",
                            DB.id_status + "=" + String.valueOf(Job.STATUS_PENDING) + " ORDER BY " +
                            DB.id_status + " DESC," + DB.dt_execution + " DESC", iWorkerThreads);

    oJobsSet.setMaxRows(iWorkerThreads);

    iJobCount = oJobsSet.load(oConn); // Devuelve la cuenta de jobs pendientes

    // Prepara la sentencia para actualizar el estado de los jobs a Running
    sSQL = "UPDATE " + DB.k_jobs + " SET " + DB.id_status + "=" + String.valueOf(Job.STATUS_RUNNING) + "," + DB.dt_execution + "=" + DBBind.Functions.GETDATE + " WHERE " + DB.gu_job + "=?";

    if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");

    oJobStmt = oConn.prepareStatement(sSQL);

    // Para cada job, cargar su lista de miembros del tipo que corresponda y
    // cambiar el estado a Running
    for (int j=0; j<iJobCount; j++) {
      // leer los parámetros adicionales del job del campo tx_parameters
      oParams = parseParameters(oJobsSet.getString(4, j));

      // Generar un objeto temporal de tipo lista de distribución
      // para leer los valores de la lista de miembros
      if (oParams.getProperty("gu_list")!=null) {
        oDistribList = new DistributionList(oConn, oParams.getProperty("gu_list"));

        // Si la fecha de ejecución del job es null,
        // tomar la fecha actual como fecha de ejecución inmediata
        if (oJobsSet.isNull(DB.dt_execution,j))
          dtExec = dtNow;
        else
          dtExec = oJobsSet.getDate(DB.dt_execution,j);

        // Para cada tipo de lista usar el método de carga de miembros que corresponda
        switch (oDistribList.getShort(DB.tp_list)) {
          case DistributionList.TYPE_DYNAMIC:
            iLoaded += loadDynamicList(oConn, oJobsSet.getString(0, j), dtExec, oParams.getProperty("gu_list"), oDistribList.getString(DB.gu_query), oDistribList.getString(DB.gu_workarea), Atom.STATUS_PENDING);
            break;
          case DistributionList.TYPE_STATIC:
            iLoaded += loadStaticList(oConn, oJobsSet.getString(0, j), dtExec, oParams.getProperty("gu_list"), Atom.STATUS_PENDING);
            break;
          case DistributionList.TYPE_DIRECT:
View Full Code Here


    DBSubset  oJobsSet;
    int iJobCount;
    String aParams[];
    String aVariable[];
    Properties oParams;
    DistributionList oDistribList;
    Date dtNow = new Date();
    Date dtExec;
    String sSQL;
    int iLoaded = 0;

    if (DebugFile.trace) {
       DebugFile.writeln("Begin AtomFeeder.loadAtoms([Connection:"+oConn.pid()+"], " + sJobId + ")");
       DebugFile.incIdent();
     }

    // Crea un DBSubset para recorrer los jobs pendientes de ejecución

    oJobsSet = new DBSubset(DB.k_jobs,
                            "gu_job,gu_job_group,gu_workarea,id_command,tx_parameters,id_status,dt_execution,dt_finished,dt_created,dt_modified",
                            DB.gu_job + "='" + sJobId + "'", 1);


    iJobCount = oJobsSet.load(oConn); // Devuelve la cuenta de jobs pendientes

    // Prepara la sentencia para actualizar el estado de los jobs a Running
    sSQL = "UPDATE " + DB.k_jobs + " SET " + DB.id_status + "=" + String.valueOf(Job.STATUS_RUNNING) + "," + DB.dt_execution + "=" + DBBind.Functions.GETDATE + " WHERE " + DB.gu_job + "=?";

    if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ") on connection with process id. "+oConn.pid());

    oJobStmt = oConn.prepareStatement(sSQL);

    // Para cada job, cargar su lista de miembros del tipo que corresponda y
    // cambiar el estado a Running
    if (1==iJobCount) {
      // leer los parámetros adicionales del job del campo tx_parameters
      oParams = parseParameters(oJobsSet.getString(4, 0));

      // Generar un objeto temporal de tipo lista de distribución
      // para leer los valores de la lista de miembros
      if (oParams.getProperty("gu_list")!=null) {
        oDistribList = new DistributionList(oConn, oParams.getProperty("gu_list"));

        // Si la fecha de ejecución del job es null,
        // tomar la fecha actual como fecha de ejecución inmediata
        if (oJobsSet.isNull(DB.dt_execution,0))
          dtExec = dtNow;
        else
          dtExec = oJobsSet.getDate(DB.dt_execution,0);

        // Para cada tipo de lista usar el método de carga de miembros que corresponda
        switch (oDistribList.getShort(DB.tp_list)) {
          case DistributionList.TYPE_DYNAMIC:
            iLoaded += loadDynamicList(oConn, oJobsSet.getString(0, 0), dtExec, oParams.getProperty("gu_list"), oDistribList.getString(DB.gu_query), oDistribList.getString(DB.gu_workarea), iInitialStatus);
            break;
          case DistributionList.TYPE_STATIC:
            iLoaded += loadStaticList(oConn, oJobsSet.getString(0, 0), dtExec, oParams.getProperty("gu_list"), iInitialStatus);
            break;
          case DistributionList.TYPE_DIRECT:
View Full Code Here

   * @throws ClassCastException
   */
  public void store(Connection oConn, String sWorkArea, int iFlags)
    throws SQLException,IllegalArgumentException,NullPointerException,ClassCastException {

  DistributionList oDistribList = null;
  short iListType = 0;

    if (oCompUpdt==null || oContUpdt==null || oAddrUpdt==null)
      throw new SQLException("Invalid command sequece. Must call ContactLoader.prepare() before ContactLoader.store()");

    if (!test(iFlags,MODE_APPEND) && !test(iFlags,MODE_UPDATE))
      throw new IllegalArgumentException("ContactLoader.store() Flags bitmask must contain either MODE_APPEND, MODE_UPDATE or both");

    if (!test(iFlags,WRITE_COMPANIES) && !test(iFlags,WRITE_CONTACTS))
      throw new IllegalArgumentException("ContactLoader.store() Flags bitmask must contain either WRITE_COMPANIES, WRITE_CONTACTS or both");

    if (null==sWorkArea)
      throw new NullPointerException("ContactLoader.store() Default WorkArea cannot be null");

    if (null==getColNull(gu_company) && test(iFlags,WRITE_COMPANIES) && test(iFlags,MODE_UPDATE) && !test(iFlags,MODE_APPEND))
      throw new NullPointerException("ContactLoader.store() gu_company cannot be null when using UPDATE mode");

    if (null==getColNull(gu_contact) && test(iFlags,WRITE_CONTACTS) && test(iFlags,MODE_UPDATE) && !test(iFlags,MODE_APPEND))
      throw new NullPointerException("ContactLoader.store() gu_contact cannot be null when using UPDATE mode");

    if (null==getColNull(gu_address) && test(iFlags,WRITE_ADDRESSES) && test(iFlags,MODE_UPDATE) && !test(iFlags,MODE_APPEND))
      throw new NullPointerException("ContactLoader.store() gu_address cannot be null when using UPDATE mode");

    if (test(iFlags,ADD_TO_LIST)) {
    if (!test(iFlags,MODE_APPEND))
        throw new IllegalArgumentException("ContactLoader.store() MODE_APPEND is required if ADD_TO_LIST is set");
    if (!test(iFlags,WRITE_CONTACTS) && !test(iFlags,WRITE_COMPANIES))
        throw new IllegalArgumentException("ContactLoader.store() WRITE_CONTACTS or WRITE_COMPANIES are required if ADD_TO_LIST is set");
    if (!test(iFlags,WRITE_ADDRESSES))
        throw new IllegalArgumentException("ContactLoader.store() WRITE_ADDRESSES is required if ADD_TO_LIST is set");
    if (get(gu_list)==null) {
        throw new IllegalArgumentException("ContactLoader.store() value for gu_list column is required if ADD_TO_LIST is set");
      } else {
    if (oListsMap.containsKey(get(gu_list))) {
      oDistribList = oListsMap.get(get(gu_list));
      iListType = oDistribList.getShort("tp_list");
      if (iListType!=DistributionList.TYPE_STATIC &&
          iListType!=DistributionList.TYPE_DIRECT &&
          iListType!=DistributionList.TYPE_BLACK)
            throw new IllegalArgumentException("ContactLoader.store() type for list "+get(gu_list)+" must be either STATIC, DIRECT or BLACK but it is "+String.valueOf(iListType));
    } else {
        PreparedStatement oList = oConn.prepareStatement("SELECT tp_list FROM k_lists WHERE gu_workarea=? AND gu_list=?",
                               ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      oList.setString(1, sWorkArea);
      oList.setObject(2, get(gu_list), Types.CHAR);
      ResultSet oRist = oList.executeQuery();
      boolean bFoundList = oRist.next();
      if (bFoundList) {
        iListType = oRist.getShort(1);
        oDistribList = new DistributionList();
        oDistribList.put("gu_list", get(gu_list));
        oDistribList.put("tp_list", iListType);
        oDistribList.put("gu_workarea", sWorkArea);
      oListsMap.put(getColNull(gu_list), oDistribList);
      }
      oRist.close();
      oList.close();
      if (!bFoundList)
            throw new IllegalArgumentException("ContactLoader.store() List "+get(gu_list)+" not found for Work Area "+sWorkArea+" at table l_lists");
      if (iListType!=DistributionList.TYPE_STATIC &&
          iListType!=DistributionList.TYPE_DIRECT &&
          iListType!=DistributionList.TYPE_BLACK)
            throw new IllegalArgumentException("ContactLoader.store() type for list "+get(gu_list)+" must be either STATIC, DIRECT or BLACK but it is "+String.valueOf(iListType));
      } // fi (containsKey(gu_list))
    } // fi (gu_list)
    } // fi (ADD_TO_LIST)

    if (DebugFile.trace) {
      DebugFile.writeln("Begin ContactLoader.store([Connection],"+sWorkArea+","+
                   (test(iFlags, MODE_APPEND) ? "MODE_APPEND" : "")+
                   (test(iFlags, MODE_UPDATE) ? "|MODE_UPDATE" : "")+
                   (test(iFlags, WRITE_LOOKUPS) ? "|WRITE_LOOKUPS" : "")+
                   (test(iFlags, WRITE_CONTACTS) ? "|WRITE_CONTACTS" : "")+
                   (test(iFlags, WRITE_ADDRESSES) ? "|WRITE_ADDRESSES" : "")+
                   (test(iFlags, NO_DUPLICATED_NAMES) ? "|NO_DUPLICATED_NAMES" : "")+
                   (test(iFlags, NO_DUPLICATED_MAILS) ? "|NO_DUPLICATED_MAILS" : "")+
                   (test(iFlags, ADD_TO_LIST) ? "|ADD_TO_LIST" : "")+")");
      DebugFile.incIdent();
      StringBuffer oRow = new StringBuffer();
      oRow.append('{');
      oRow.append(ColumnNames[0]+"=");
      oRow.append(aValues[0]==null ? "null" : aValues[0]);
      for (int d=1; d<aValues.length; d++) {
        oRow.append(","+ColumnNames[d]+"=");
        oRow.append(aValues[d]==null ? "null" : aValues[d]);
      } // next
      oRow.append('}');
      DebugFile.writeln(oRow.toString());
    }

    int iAffected;
    Timestamp tsNow = new Timestamp(new Date().getTime());

    if (null==get(gu_workarea)) {
      if (DebugFile.trace) DebugFile.writeln("setting workarea to "+sWorkArea);
      put(gu_workarea, sWorkArea);
    } else {
      if (DebugFile.trace) DebugFile.writeln("workarea for current record is "+getColNull(gu_workarea));
    }
    if (test(iFlags,WRITE_COMPANIES) && getColNull(gu_company)==null && getColNull(nm_legal)!=null)
      put(gu_company, getCompanyGuid(oConn, aValues[nm_legal], get(gu_workarea)));

    if (test(iFlags,WRITE_CONTACTS) && getColNull(gu_contact)==null) {
      if (test(iFlags,ALLOW_DUPLICATED_PASSPORTS) && !test(iFlags,NO_DUPLICATED_MAILS)) {
        put(gu_contact, Gadgets.generateUUID());
      } else if (test(iFlags,NO_DUPLICATED_MAILS)) {
        put(gu_contact, getContactForEmail(oConn, aValues[tx_email], get(gu_workarea)));
        if (getColNull(gu_contact)==null && !test(iFlags,ALLOW_DUPLICATED_PASSPORTS))
          put(gu_contact, getContactGuid(oConn, aValues[sn_passport], get(gu_workarea)));
      } else if (!test(iFlags,ALLOW_DUPLICATED_PASSPORTS)) {
        put(gu_contact, getContactGuid(oConn, aValues[sn_passport], get(gu_workarea)));
      } else {
        put(gu_contact, Gadgets.generateUUID());
      }
    }

    if (test(iFlags,WRITE_ADDRESSES) && aValues[gu_address]==null)
      put(gu_address, getAddressGuid(oConn, aValues[ix_address], get(gu_workarea), get(gu_contact), get(gu_company), iFlags));

    if (test(iFlags,WRITE_COMPANIES) && (getColNull(gu_company)!=null || getColNull(nm_legal)!=null)) {
      if (test(iFlags,WRITE_LOOKUPS)) {
        addLookUp("k_companies_lookup", "id_sector", getColNull(id_sector), oConn, oCompLook, oCompSectorsMap);
        addLookUp("k_companies_lookup", "id_status", getColNull(id_company_status), oConn, oCompLook, oCompStatusMap);
        addLookUp("k_companies_lookup", "tp_company", getColNull(tp_company), oConn, oCompLook, oCompTypesMap);
      } // if (test(WRITE_LOOKUPS))

      iAffected = 0;
      if ((test(iFlags,MODE_UPDATE) || test(iFlags,WRITE_CONTACTS)) &&
          (getColNull(nm_legal)!=null || getColNull(gu_company)!=null)) {
        if (DebugFile.trace) DebugFile.writeln("COMPANY MODE_UPDATE AND IS NOT NEW COMPANY");
        oCompUpdt.setString(1, getColNull(nm_legal));
         if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(2, "+aValues[gu_workarea]+", Types.CHAR)");
        oCompUpdt.setObject(2, aValues[gu_workarea], Types.CHAR);
        oCompUpdt.setString(3, getColNull(nm_commercial));
        if (aValues[dt_modified]==null)
          oCompUpdt.setTimestamp(4, tsNow);
        else {
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(4, "+aValues[dt_modified]+", Types.TIMESTAMP)");
          oCompUpdt.setObject(4, aValues[dt_modified], Types.TIMESTAMP);
        }
        if (aValues[dt_founded]==null)
          oCompUpdt.setNull(5, Types.TIMESTAMP);
        else {
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(5, "+aValues[dt_founded]+", Types.TIMESTAMP)");
          oCompUpdt.setObject(5, aValues[dt_founded], Types.TIMESTAMP);
        }
        oCompUpdt.setString(6, getColNull(id_legal));
        oCompUpdt.setString(7, getColNull(id_sector));
        oCompUpdt.setString(8, getColNull(id_company_status));
        oCompUpdt.setString(9, getColNull(id_company_ref));
        oCompUpdt.setString(10, getColNull(tp_company));
        oCompUpdt.setString(11, getColNull(gu_geozone));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(12, "+aValues[nu_employees]+", Types.INTEGER)");
        oCompUpdt.setObject(12, aValues[nu_employees], Types.INTEGER);
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(13, "+aValues[im_revenue]+", Types.FLOAT)");
        oCompUpdt.setObject(13, aValues[im_revenue], Types.FLOAT);
        oCompUpdt.setString(14, getColNull(gu_sales_man));
        oCompUpdt.setString(15, getColNull(tx_franchise));
        oCompUpdt.setString(16, getColNull(de_company));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(17,"+aValues[gu_company]+")");
        oCompUpdt.setString(17, (String) aValues[gu_company]);
        oCompUpdt.setString(18, (String) aValues[nm_legal]);
        oCompUpdt.setString(19, (String) aValues[gu_workarea]);
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oCompUpdt)");
        iAffected = oCompUpdt.executeUpdate();
        if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));

        if (test(iFlags,ADD_TO_LIST) && iListType==DistributionList.TYPE_DIRECT) {
          PreparedStatement oUdlm = oConn.prepareStatement("UPDATE "+DB.k_x_list_members+" SET "+
                      DB.dt_modified+"=?,"+DB.tx_name+"=?,"+DB.tx_surname+"=?,"+
                      DB.mov_phone+"=? WHERE "+DB.gu_list+"=? AND "+DB.tx_email+"=?");
        oUdlm.setTimestamp(1, new Timestamp(new Date().getTime()));
        oUdlm.setObject(2, get(tx_name), Types.VARCHAR);
      oUdlm.setObject(3, get(tx_surname), Types.VARCHAR);
      oUdlm.setObject(4, get(mov_phone), Types.VARCHAR);
      oUdlm.setObject(5, get(gu_list), Types.CHAR);
      oUdlm.setObject(6, get(tx_email), Types.VARCHAR);
      oUdlm.executeUpdate();
      oUdlm.close();
        }

      }

      if (test(iFlags,MODE_APPEND) && (iAffected==0)) {
        if (DebugFile.trace) DebugFile.writeln("COMPANY MODE_APPEND AND affected=0");
        oCompInst.setString(1, getColNull(nm_legal));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(2, "+aValues[gu_workarea]+" "+getColNull(gu_workarea)+", Types.CHAR)");
        oCompInst.setObject(2, aValues[gu_workarea], Types.CHAR);
        oCompInst.setString(3, getColNull(nm_commercial));
        if (aValues[dt_modified]==null) {
          oCompInst.setTimestamp(4, tsNow);
        } else {
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(4, "+aValues[dt_modified]+", Types.TIMESTAMP)");
          oCompInst.setObject(4, aValues[dt_modified], Types.TIMESTAMP);
        }
        if (aValues[dt_founded]==null) {
          oCompInst.setNull(5, Types.TIMESTAMP);
        } else {
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(5, "+aValues[dt_founded]+", Types.TIMESTAMP)");
          oCompInst.setObject(5, aValues[dt_founded], Types.TIMESTAMP);
        }
        oCompInst.setString(6, getColNull(id_legal));
        oCompInst.setString(7, getColNull(id_sector));
        oCompInst.setString(8, getColNull(id_company_status));
        oCompInst.setString(9, getColNull(id_company_ref));
        oCompInst.setString(10, getColNull(tp_company));
        oCompInst.setString(11, getColNull(gu_geozone));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(12, "+aValues[nu_employees]+", Types.INTEGER)");
        oCompInst.setObject(12, aValues[nu_employees], Types.INTEGER);
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(13, "+aValues[im_revenue]+", Types.FLOAT)");
        oCompInst.setObject(13, aValues[im_revenue], Types.FLOAT);
        oCompInst.setString(14, getColNull(gu_sales_man));
        oCompInst.setString(15, getColNull(tx_franchise));
        oCompInst.setString(16, getColNull(de_company));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(17,"+aValues[gu_company]+")");
        oCompInst.setString(17, (String) aValues[gu_company]);
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oCompInst)");
        iAffected = oCompInst.executeUpdate();
        if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));
      }
    } // fi (test(iFlags,WRITE_COMPANIES) && (getColNull(gu_company)!=null || getColNull(nm_legal)!=null))

    if (test(iFlags,WRITE_CONTACTS)) {
      if (test(iFlags,WRITE_LOOKUPS)) {
        addLookUp("k_contacts_lookup", "id_status", getColNull(id_contact_status), oConn, oContLook, oContStatusMap);
        addLookUp("k_contacts_lookup", "de_title", getColNull(de_title), oConn, oContLook, oContTitlesMap);
        addLookUp("k_contacts_lookup", "id_gender", getColNull(id_gender), oConn, oContLook, oContGendersMap);
        addLookUp("k_contacts_lookup", "tx_dept", getColNull(tx_dept), oConn, oContLook, oContDeptsMap);
        addLookUp("k_contacts_lookup", "tx_division", getColNull(tx_division), oConn, oContLook, oContDivsMap);
      } // if (test(WRITE_LOOKUPS))

      iAffected = 0;
      if (DebugFile.trace) DebugFile.writeln("MODE_UPDATE="+String.valueOf(test(iFlags,MODE_UPDATE))+" "+(getColNull(sn_passport)==null ? "sn_passport IS NULL" : "sn_passport IS NOT NULL")+" "+(getColNull(gu_contact)==null ? "gu_contact IS NULL" : "gu_contact IS NOT NULL"));
      if (test(iFlags,MODE_UPDATE) && (getColNull(sn_passport)!=null || getColNull(gu_contact)!=null)) {
        if (DebugFile.trace) DebugFile.writeln("CONTACT MODE_UPDATE AND IS NOT NEW CONTACT");
        oContUpdt.setObject(1, aValues[gu_workarea], Types.CHAR);
        oContUpdt.setString(2, getColNull(tx_nickname));
        oContUpdt.setString(3, getColNull(tx_pwd));
        oContUpdt.setString(4, getColNull(tx_challenge));
        oContUpdt.setString(5, getColNull(tx_reply));
        oContUpdt.setObject(6, aValues[dt_pwd_expires], Types.TIMESTAMP);
        if (aValues[dt_modified]==null)
          oContUpdt.setTimestamp(7, tsNow);
        else
          oContUpdt.setObject(7, aValues[dt_modified], Types.TIMESTAMP);
        oContUpdt.setString(8, getColNull(gu_writer));
        if (test(iFlags,WRITE_COMPANIES))
          oContUpdt.setString(9, getColNull(gu_company));
        else
          oContUpdt.setNull(9,Types.CHAR);
        oContUpdt.setString(10, getColNull(id_contact_status));
        oContUpdt.setString(11, getColNull(id_contact_ref));
        oContUpdt.setString(12, getColNull(tx_name));
        oContUpdt.setString(13, getColNull(tx_surname));
        oContUpdt.setString(14, getColNull(de_title));
        oContUpdt.setString(15, getColNull(id_gender));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(16, "+aValues[dt_birth]+", Types.TIMESTAMP)");
        if (null==aValues[dt_birth])
          oContUpdt.setNull(16, Types.TIMESTAMP);
        else if (aValues[dt_birth].getClass().getName().equals("java.util.Date"))
          oContUpdt.setObject(16, new Timestamp(((java.util.Date)aValues[dt_birth]).getTime()), Types.TIMESTAMP);
        else
          oContUpdt.setObject(16, aValues[dt_birth], Types.TIMESTAMP);         
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(17, "+aValues[ny_age]+", Types.INTEGER)");
        oContUpdt.setObject(17, aValues[ny_age], Types.INTEGER);
        oContUpdt.setString(18, getColNull(sn_passport));
        oContUpdt.setString(19, getColNull(tp_passport));
        oContUpdt.setString(20, getColNull(sn_drivelic));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject(21, "+aValues[dt_drivelic]+", Types.TIMESTAMP)");
        oContUpdt.setObject(21, aValues[dt_drivelic], Types.TIMESTAMP);
        oContUpdt.setString(22, getColNull(tx_dept));
        oContUpdt.setString(23, getColNull(tx_division));
        oContUpdt.setString(24, getColNull(gu_geozone));
        if (getColNull(id_nationality)==null)
          oContUpdt.setNull(25, Types.CHAR);
    else
          oContUpdt.setString(25, getColNull(id_nationality));
        if (getColNull(tx_comments)==null) {
          oContUpdt.setNull(26, Types.VARCHAR);
        } else {
          oContUpdt.setString(26, Gadgets.left((String) aValues[tx_comments], 254));
        }
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(27,"+aValues[gu_contact]+")");
        oContUpdt.setString(27, (String) aValues[gu_contact]);
        if (test(iFlags,NO_DUPLICATED_NAMES)) {
          oContUpdt.setString(28, getColNull(tx_name));
          oContUpdt.setString(29, getColNull(tx_surname));
          oContUpdt.setString(30, (String) aValues[gu_workarea]);
        } else {
          oContUpdt.setNull(28, Types.VARCHAR);
          oContUpdt.setNull(29, Types.VARCHAR);
          oContUpdt.setNull(30, Types.CHAR);
        }
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oContUpdt)");
          iAffected = oContUpdt.executeUpdate();
        if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));
      } // fi (MODE_UPDATE && !bIsNewContact)

      if (test(iFlags,MODE_APPEND)) {
        if (iAffected==0) {
          if (DebugFile.trace) DebugFile.writeln("CONTACT MODE_APPEND AND affected=0");
          oContInst.setObject(1, aValues[gu_workarea], Types.CHAR);
          oContInst.setString(2, getColNull(tx_nickname));
          oContInst.setString(3, getColNull(tx_pwd));
          oContInst.setString(4, getColNull(tx_challenge));
          oContInst.setString(5, getColNull(tx_reply));
          oContInst.setObject(6, aValues[dt_pwd_expires], Types.TIMESTAMP);
          if (aValues[dt_modified]==null)
            oContInst.setTimestamp(7, tsNow);
          else
            oContInst.setObject(7, aValues[dt_modified], Types.TIMESTAMP);
          oContInst.setString(8, getColNull(gu_writer));
          if (test(iFlags,WRITE_COMPANIES))
            oContInst.setString(9, getColNull(gu_company));
          else
            oContInst.setNull(9,Types.CHAR);
          oContInst.setString(10, getColNull(id_contact_status));
          oContInst.setString(11, getColNull(id_contact_ref));
          oContInst.setString(12, getColNull(tx_name));
          oContInst.setString(13, getColNull(tx_surname));
          oContInst.setString(14, getColNull(de_title));
          oContInst.setString(15, getColNull(id_gender));
          if (null==aValues[dt_birth])
            oContInst.setNull(16, Types.TIMESTAMP);
          else if (aValues[dt_birth].getClass().getName().equals("java.util.Date"))
            oContInst.setObject(16, new Timestamp(((java.util.Date)aValues[dt_birth]).getTime()), Types.TIMESTAMP);
          else
            oContInst.setObject(16, aValues[dt_birth], Types.TIMESTAMP);
          oContInst.setObject(17, aValues[ny_age], Types.INTEGER);
          oContInst.setString(18, getColNull(sn_passport));
          oContInst.setString(19, getColNull(tp_passport));
          oContInst.setString(20, getColNull(sn_drivelic));
          oContInst.setObject(21, aValues[dt_drivelic], Types.TIMESTAMP);
          oContInst.setString(22, getColNull(tx_dept));
          oContInst.setString(23, getColNull(tx_division));
          oContInst.setString(24, getColNull(gu_geozone));
          if (getColNull(id_nationality)==null)
            oContInst.setNull(25, Types.CHAR);
      else
            oContInst.setString(25, getColNull(id_nationality));
          if (getColNull(tx_comments)==null) {
            oContInst.setNull(26, Types.VARCHAR);
          } else {
            oContInst.setString(26, Gadgets.left((String) aValues[tx_comments], 254));
          }
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(27,"+aValues[gu_contact]+")");
          oContInst.setString(27, (String) aValues[gu_contact]);
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oContInst)");
          iAffected = oContInst.executeUpdate();
          if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));
       
        } // fi (iAffected==0)
      } // fi (MODE_APPEND)
    } // fi (WRITE_CONTACTS)

    if (test(iFlags,WRITE_LOOKUPS)) {
      addLookUp("k_addresses_lookup", "tp_location", getColNull(tp_location), oConn, oAddrLook, oAddrLocsMap);
      addLookUp("k_addresses_lookup", "tp_street", getColNull(tp_street), oConn, oAddrLook, oAddrTypesMap);
      addLookUp("k_addresses_lookup", "tx_salutation", getColNull(tp_street), oConn, oAddrLook, oAddrSalutMap);
    } // if (test(WRITE_LOOKUPS))

    iAffected = 0;
    if (test(iFlags,MODE_UPDATE) && getColNull(gu_address)!=null) {
      if (DebugFile.trace) DebugFile.writeln("ADDRESS MODE_UPDATE AND IS NOT NEW ADDRESS");

      if (null!=aValues[ix_address])
        oAddrUpdt.setObject(1, aValues[ix_address], Types.INTEGER);
      else {
        if (test(iFlags,WRITE_CONTACTS))
          oAddrUpdt.setInt(1, Address.nextLocalIndex(oConn, "k_x_contact_addr", "gu_contact", (String) aValues[gu_contact]));
        else
          oAddrUpdt.setInt(1, Address.nextLocalIndex(oConn, "k_x_company_addr", "gu_company", (String) aValues[gu_company]));
      }
      oAddrUpdt.setObject(2, aValues[gu_workarea], Types.CHAR);
      if (null!=aValues[bo_active])
        oAddrUpdt.setObject(3, aValues[bo_active], Types.SMALLINT);
      else
        oAddrUpdt.setShort(3, (short)1);
      if (aValues[dt_modified]==null)
        oAddrUpdt.setTimestamp(4, tsNow);
      else
        oAddrUpdt.setObject(4, aValues[dt_modified], Types.TIMESTAMP);
      oAddrUpdt.setString(5, getColNull(tp_location));
      if (test(iFlags,WRITE_COMPANIES))
        oAddrUpdt.setString(6, (String) (getColNull(nm_commercial)==null ? getColNull(nm_legal) : aValues[nm_commercial]));
      else
        oAddrUpdt.setNull(6,Types.VARCHAR);
      oAddrUpdt.setString(7, getColNull(tp_street));
      oAddrUpdt.setString(8, getColNull(nm_street));
      oAddrUpdt.setString(9, getColNull(nu_street));
      oAddrUpdt.setString(10, getColNull(tx_addr1));
      oAddrUpdt.setString(11, getColNull(tx_addr2));
      oAddrUpdt.setString(12, getColNull(id_country));
      oAddrUpdt.setString(13, getColNull(nm_country));
      oAddrUpdt.setString(14, getColNull(id_state));
      oAddrUpdt.setString(15, getColNull(nm_state));
      oAddrUpdt.setString(16, getColNull(mn_city));
      if (getColNull(zipcode)==null)
        oAddrUpdt.setNull(17, Types.VARCHAR);
      else
        oAddrUpdt.setString(17, getColNull(zipcode));
      oAddrUpdt.setString(18, getColNull(work_phone));
      oAddrUpdt.setString(19, getColNull(direct_phone));
      oAddrUpdt.setString(20, getColNull(home_phone));
      oAddrUpdt.setString(21, getColNull(mov_phone));
      oAddrUpdt.setString(22, getColNull(fax_phone));
      oAddrUpdt.setString(23, getColNull(other_phone));
      oAddrUpdt.setString(24, getColNull(po_box));
      oAddrUpdt.setString(25, getColNull(tx_email));
      oAddrUpdt.setString(26, getColNull(tx_email_alt));
      oAddrUpdt.setString(27, getColNull(url_addr));
      oAddrUpdt.setObject(28, aValues[coord_x], Types.FLOAT);
      oAddrUpdt.setObject(29, aValues[coord_y], Types.FLOAT);
      oAddrUpdt.setString(30, getColNull(contact_person));
      oAddrUpdt.setString(31, getColNull(tx_salutation));
      oAddrUpdt.setString(32, getColNull(id_address_ref));
      oAddrUpdt.setString(33, getColNull(tx_remarks));
      if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(34,"+aValues[gu_address]+")");
      oAddrUpdt.setString(34, (String) aValues[gu_address]);
      if (test(iFlags,NO_DUPLICATED_MAILS)) {
        oAddrUpdt.setString(35, getColNull(tx_email));
        oAddrUpdt.setString(36, (String) aValues[gu_workarea]);
      } else {
        oAddrUpdt.setNull(35, Types.VARCHAR);
        oAddrUpdt.setNull(36, Types.CHAR);
      }
      if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oAddrUpdt)");
      iAffected = oAddrUpdt.executeUpdate();
      if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));
    }

    if (test(iFlags,MODE_APPEND)) {
      if (iAffected==0) {
        if (DebugFile.trace) DebugFile.writeln("ADDRESS MODE_APPEND AND affected=0");

        if (null!=aValues[ix_address])
          oAddrInst.setObject(1, aValues[ix_address], Types.INTEGER);
        else
          oAddrInst.setInt(1, Address.nextLocalIndex(oConn, "k_x_contact_addr", "gu_contact", (String) aValues[gu_contact]));
        oAddrInst.setString(2, (String) aValues[gu_workarea]);
        if (null!=aValues[bo_active])
          oAddrInst.setObject(3, aValues[bo_active], Types.SMALLINT);
        else
          oAddrInst.setShort(3, (short)1);
        if (aValues[dt_modified]==null)
          oAddrInst.setTimestamp(4, tsNow);
        else
          oAddrInst.setObject(4, aValues[dt_modified], Types.TIMESTAMP);
        oAddrInst.setString(5, getColNull(tp_location));
        if (test(iFlags,WRITE_COMPANIES))
          oAddrInst.setString(6, (String) (getColNull(nm_commercial)==null ? getColNull(nm_legal) : aValues[nm_commercial]));
        else
          oAddrInst.setNull(6,Types.VARCHAR);
        oAddrInst.setString(7, getColNull(tp_street));
        oAddrInst.setString(8, getColNull(nm_street));
        oAddrInst.setString(9, getColNull(nu_street));
        oAddrInst.setString(10, getColNull(tx_addr1));
        oAddrInst.setString(11, getColNull(tx_addr2));
        oAddrInst.setString(12, getColNull(id_country));
        oAddrInst.setString(13, getColNull(nm_country));
        oAddrInst.setString(14, getColNull(id_state));
        oAddrInst.setString(15, getColNull(nm_state));
        oAddrInst.setString(16, getColNull(mn_city));
        if (getColNull(zipcode)==null)
          oAddrInst.setNull(17, Types.VARCHAR);
        else
          oAddrInst.setString(17, getColNull(zipcode));
        oAddrInst.setString(18, Gadgets.left(getColNull(work_phone),16));
        oAddrInst.setString(19, Gadgets.left(getColNull(direct_phone),16));
        oAddrInst.setString(20, Gadgets.left(getColNull(home_phone),16));
        oAddrInst.setString(21, Gadgets.left(getColNull(mov_phone),16));
        oAddrInst.setString(22, Gadgets.left(getColNull(fax_phone),16));
        oAddrInst.setString(23, Gadgets.left(getColNull(other_phone),16));
        oAddrInst.setString(24, getColNull(po_box));
        oAddrInst.setString(25, getColNull(tx_email));
        oAddrInst.setString(26, getColNull(tx_email_alt));
        oAddrInst.setString(27, getColNull(url_addr));
        oAddrInst.setObject(28, aValues[coord_x], Types.FLOAT);
        oAddrInst.setObject(29, aValues[coord_y], Types.FLOAT);
        oAddrInst.setString(30, getColNull(contact_person));
        oAddrInst.setString(31, getColNull(tx_salutation));
        oAddrInst.setString(32, getColNull(id_address_ref));
        oAddrInst.setString(33, getColNull(tx_remarks));
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(34,"+aValues[gu_address]+")");
        oAddrInst.setString(34, (String) aValues[gu_address]);
        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oAddrInst)");
        iAffected = oAddrInst.executeUpdate();
       
        if (DebugFile.trace) DebugFile.writeln("affected="+String.valueOf(iAffected));

        if (test(iFlags,WRITE_COMPANIES) && !test(iFlags,WRITE_CONTACTS)) {
          if (DebugFile.trace) DebugFile.writeln("Writting link between company and address");
          oCompAddr.setString(1, (String) aValues[gu_company]);
          oCompAddr.setString(2, (String) aValues[gu_address]);
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oCompAddr)");
          oCompAddr.executeUpdate();
        } else if (test(iFlags,WRITE_CONTACTS)) {
          if (DebugFile.trace) DebugFile.writeln("Writting link between contact and address");
          oContAddr.setString(1, (String) aValues[gu_contact]);
          oContAddr.setString(2, (String) aValues[gu_address]);
          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(oContAddr)");
          oContAddr.executeUpdate();
        }

        if (test(iFlags,ADD_TO_LIST)) {
          if (test(iFlags,WRITE_CONTACTS))
          oDistribList.addContact(oConn, (String) aValues[gu_contact]);
        else if (test(iFlags,WRITE_COMPANIES))
          oDistribList.addCompany(oConn, (String) aValues[gu_company]);         
      }
      } else {
        if (test(iFlags,ADD_TO_LIST)) {
          PreparedStatement oMmbr;
          PreparedStatement oUdlm;
          if (test(iFlags,WRITE_CONTACTS)) {
            oMmbr = oConn.prepareStatement("SELECT NULL FROM k_x_list_members WHERE gu_list=? AND gu_contact=?",
                             ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      oMmbr.setObject(1, get(gu_list), Types.CHAR);
      oMmbr.setObject(2, get(gu_contact), Types.CHAR);
      ResultSet oRmbr = oMmbr.executeQuery();
      boolean bMmbrExists = oRmbr.next();
      oRmbr.close();
      oMmbr.close();
      if (bMmbrExists) {
        if (iListType==DistributionList.TYPE_DIRECT) {
          oUdlm = oConn.prepareStatement("UPDATE "+DB.k_x_list_members+" SET "+
                        DB.dt_modified+"=?,"+DB.tx_name+"=?,"+DB.tx_surname+"=?,"+
                        DB.mov_phone+"=? WHERE "+DB.gu_list+"=? AND "+DB.tx_email+"=?");
          oUdlm.setTimestamp(1, new Timestamp(new Date().getTime()));
          oUdlm.setObject(2, get(tx_name), Types.VARCHAR);
          oUdlm.setObject(3, get(tx_surname), Types.VARCHAR);
          oUdlm.setObject(4, get(mov_phone), Types.VARCHAR);
          oUdlm.setObject(5, get(gu_list), Types.CHAR);
          oUdlm.setObject(6, get(tx_email), Types.VARCHAR);
          oUdlm.executeUpdate();
          oUdlm.close();
        }
        } else {
        oDistribList.addContact(oConn, (String) aValues[gu_contact]);
      }
          } else if (test(iFlags,WRITE_COMPANIES)) {
            oMmbr = oConn.prepareStatement("SELECT NULL FROM k_x_list_members WHERE gu_list=? AND gu_company=?",
                             ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      oMmbr.setObject(1, get(gu_list), Types.CHAR);
      oMmbr.setObject(2, get(gu_company), Types.CHAR);
      ResultSet oRmbr = oMmbr.executeQuery();
      boolean bMmbrExists = oRmbr.next();
      oRmbr.close();
      oMmbr.close();
      if (bMmbrExists) {
        if (iListType==DistributionList.TYPE_DIRECT) {
          oUdlm = oConn.prepareStatement("UPDATE "+DB.k_x_list_members+" SET "+
                        DB.dt_modified+"=?,"+DB.mov_phone+"=? "+
                        "WHERE "+DB.gu_list+"=? AND "+DB.tx_email+"=?");
          oUdlm.setTimestamp(1, new Timestamp(new Date().getTime()));
          oUdlm.setObject(4, get(mov_phone), Types.VARCHAR);
          oUdlm.setObject(5, get(gu_list), Types.CHAR);
          oUdlm.setObject(6, get(tx_email), Types.VARCHAR);
          oUdlm.executeUpdate();
          oUdlm.close();
        }
        } else {
        oDistribList.addCompany(oConn, (String) aValues[gu_company]);
      }
          }
      }     
      } // fi (iAffected==0)
    } // fi test(iFlags,MODE_APPEND))
View Full Code Here

    // ---------------------------------------------------------------------------

  public ActivityAudienceLoader() {
    aValues = new Object[ColumnNames.length];
    Arrays.fill(aValues, null);
    oDstLst = new DistributionList();
    oDstLst.put (DB.tp_list, DistributionList.TYPE_STATIC);   
    oCntLdr = new ContactLoader();
    oAcAuInsr = oAcAuLook = null;
    oOriginsMap = new HashMap();
  }
View Full Code Here

                sLId.charAt(0)=='{' && sLId.charAt(sLId.length()-1)=='}') {
              bHasLists=true;
              iListCount++;
              // *******************************
              // Resolve list name to member set
              DistributionList oLst;
              if (sLId.charAt(0)=='{') {
                oLst = new DistributionList(oAdCn, sLId.substring(1,sLId.length()-1), sWorkAreaId);
                if (oLst.isNull(DB.gu_list)) {
                  if (DebugFile.trace) DebugFile.decIdent();
                  throw new AddressException("RecipientsHelper.parseRecipientsList() list "+sLId.substring(1,sLId.length()-1)+" not found");
                }
              } else {
                oLst = new DistributionList(oAdCn, sLId.substring(sLId.indexOf('@')+1,sLId.indexOf('.')));
                if (oLst.isNull(DB.gu_list)) {
                  if (DebugFile.trace) DebugFile.decIdent();
                  throw new AddressException("RecipientsHelper.parseRecipientsList() list "+sLId.substring(sLId.indexOf('@')+1,sLId.indexOf('.'))+" not found");
                }
              }
              String sPer = oLst.getStringNull(DB.de_list,null);
              String sLst = oLst.activeMembers(oAdCn);
              if (sLst.length()>0) {
                String[] aLst = Gadgets.split(sLst,',');
                int iLst = aLst.length;
                if (null==aBccAddrs) {
                  iPos = 0;
View Full Code Here

               } else if (nMaccs>1) {      
                 System.out.println("Ambiguous name for mailing account "+oDbb.getProperty("mail.account"));
                 nErrs++;
               } else {
                 System.out.println("Composing message...");
                 DistributionList oLst = new DistributionList(oCon, oLists.getString(0,0));
                 oLists = null;
                 System.out.println("Getting mail account...");
                 MailAccount oAcc = new MailAccount(oCon, oMaccs.getString(0,0));
                 ACLUser oUsr = new ACLUser(oCon, oAcc.getString(DB.gu_user));
                 System.out.println("Got mail");
                 String sMBoxDir = DBStore.MBoxDirectory(oDbb.getProfileName(),
                                                       oUsr.getInt(DB.id_domain),
                                                       oUsr.getString(DB.gu_workarea));
                 System.out.println("mbox directory is "+sMBoxDir);
                 System.out.println("Opening mail session... ");
                 oHnl = new SessionHandler(oAcc);
        
                 oSto = DBStore.open (oHnl.getSession(), oDbb.getProfileName(), sMBoxDir,
                                      oUsr.getString(DB.gu_user), oUsr.getString(DB.tx_pwd));
                 oFld = oSto.openDBFolder("outbox", DBFolder.READ_WRITE);
                 System.out.println("Creating message template...");
        
                 DBMimeMessage oMsg = DraftsHelper.draftMessage(oFld, oDbb.getProperty("mail.host","127.0.0.1"),
                                                                oUsr.getString(DB.gu_workarea),
                                                                oUsr.getString(DB.gu_user), sType);
                 DraftsHelper.draftUpdate (oCon, oUsr.getInt(DB.id_domain),
                                           oUsr.getString(DB.gu_workarea),
                                           oMsg.getMessageGuid(),
                                           DBCommand.queryStr(oCon, "SELECT "+DB.id_message+" FROM "+DB.k_mime_msgs+
                                             " WHERE "+DB.gu_mimemsg+"='"+oMsg.getMessageGuid()+"'"),
                                           oLst.getString(DB.tx_from),
                                           oLst.getStringNull(DB.tx_reply,oLst.getString(DB.tx_from)),
                                           oLst.getStringNull(DB.tx_sender,oLst.getString(DB.tx_from)),
                                           oLst.getStringNull(DB.tx_subject,""),
                                           "text/"+sType+"; charset=utf-8",
                                           sBody, null, null, null);

                 System.out.println("Message template successfully composed");
                 String sGuJob = null;
                 if (null!=oDbb.getProperty("mail.job.title")) {
                   oStm = oCon.prepareStatement("SELECT "+DB.gu_job+" FROM "+DB.k_jobs+" WHERE "+
                                                DB.tl_job+"=? AND "+DB.gu_workarea+"=?");
                   oStm.setString(1, oDbb.getProperty("mail.job.title"));
                   oStm.setString(2, oLst.getString(DB.gu_workarea));
                   oRst = oStm.executeQuery();
                   if (oRst.next()) sGuJob = oRst.getString(1);
                   oRst.close();
                   oRst=null;
                   oStm.close();
                   oStm=null;
                 } // fi
        
                 if (null==sGuJob) {
                   oSnd = newInstance(oCon, oLst.getString(DB.gu_list),
                                      oLst.getString(DB.gu_workarea),
                                      oUsr.getString(DB.gu_user), dtNow,
                                      Job.STATUS_RUNNING,
                                      oDbb.getProperty("mail.job.title",oLst.getStringNull(DB.de_list,"")+" "+dtNow.toString()),
                                      "profile:"+oDbb.getProfileName()+
                                      ",id:"+oMsg.getMessageID()+
                                      ",message:"+oMsg.getMessageGuid()+
                                      ",account:"+oAcc.getString(DB.gu_account)+
                                      ",gu_list:"+oLst.getString(DB.gu_list)+
                                      ",personalized:"+String.valueOf(true)+
                                      ",bo_attachimages:1");
                 } else {
                   oSnd = new MimeSender();
                   oSnd.load(oCon, sGuJob);
View Full Code Here

TOP

Related Classes of com.knowgate.crm.DistributionList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.