// loop throught list and look for match
Iterator itGroup = groupList.iterator();
while (itGroup.hasNext()) {
DDNameValue nameValue = (DDNameValue) itGroup.next();
// if name matches, then...
if (group.equals(nameValue.getName())) {
// ... get the ID
groupID = nameValue.getId();
}
}
if (groupID == 0) {
errMsg = errMsg + "Account Team \"" + group + "\" not found in Group List,";
flagInsert = false;
}
}
if ((CustomEntList != null) && (CustomEntList.size() > 0)) {
Iterator it = CustomEntList.iterator();
while (it.hasNext()) {
DDNameValue ddname = (DDNameValue) it.next();
String id = ddname.getName();
String type = null;
StringTokenizer st = new StringTokenizer(id, "*");
while (st.hasMoreTokens()) {
id = (String) st.nextToken();
type = (String) st.nextToken();
}
String name = ddname.getStrid();
String customEntityValue = (String) hCols.get(name);
if (customEntityValue != null) {
if ((type != null) && type.equals("MULTIPLE")) {
String tempEnt = customEntityValue;
int indexName = name.indexOf("(");
if (indexName > 0) {
customEntityValue = customEntityValue + "*" + name.substring(0, indexName);
}
boolean customFlag = CustomFieldValues.containsKey(customEntityValue);
if (! customFlag) {
errMsg = errMsg + "Custom Field \"" + tempEnt + "\" Mapped for Entity's Does Not Exist in the database ,";
flagInsert = false;
}
}
}
}
}
if ((CustomIndList != null) && (CustomIndList.size() > 0)) {
Iterator it = CustomIndList.iterator();
while (it.hasNext()) {
DDNameValue ddname = (DDNameValue) it.next();
String id = ddname.getName();
String type = null;
StringTokenizer st = new StringTokenizer(id, "*");
while (st.hasMoreTokens()) {
id = (String) st.nextToken();
type = (String) st.nextToken();
}
String name = ddname.getStrid();
String customIndividualName = (String) hCols.get(name);
if (customIndividualName != null) {
if ((type != null) && type.equals("MULTIPLE")) {
String tempIndv = customIndividualName;
int indexName = name.indexOf("(");
if (indexName > 0) {
customIndividualName = customIndividualName + "*" + name.substring(0, indexName);
}
boolean customFlag = CustomFieldValues.containsKey(customIndividualName.trim());
if (!customFlag) {
errMsg = errMsg + "Custom Filed \"" + tempIndv + "\" mapped for Entity's Is Not Existing in the database ,";
flagInsert = false;
}
}
}
}
}
if (!errMsg.equals("")) {
errCounter++;
}
if (flagInsert) {
int sourceId = 0;
int sourceEn = 0;
int entId = 0;
boolean sourceFlag = sourceList.containsKey(sourceIndividual);
if (sourceFlag) {
sourceId = Integer.parseInt((String) sourceList.get(sourceIndividual));
} else {
if (sourceIndividual != null && !sourceIndividual.equals("")) {
try {
sourceId = remoteCommon.getSourceID(sourceIndividual);
} catch(Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
}
sourceFlag = sourceList.containsKey(sourceEntity);
if (sourceFlag) {
sourceEn = Integer.parseInt((String) sourceList.get(sourceEntity));
} else {
if (sourceEntity != null && !sourceEntity.equals("")) {
try {
sourceId = remoteCommon.getSourceID(sourceEntity);
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
e.printStackTrace();
}
}
}
// Get the group ID from the database
int groupID = 0;
// loop throught list and look for match
Iterator itGroup = groupList.iterator();
while (itGroup.hasNext()) {
DDNameValue nameValue = (DDNameValue) itGroup.next();
// if name matches, then...
if (group.equals(nameValue.getName())) {
// ... get the ID
groupID = nameValue.getId();
}
}
int user = 0;
// loop throught list and look for match
boolean employeeFlag = employeeList.containsKey(manager);
if (employeeFlag) {
user = Integer.parseInt((String) employeeList.get(manager));
}
if (!(website.startsWith("http://")) || (website.startsWith("https://"))) {
// added only http by default and not https
if ((website.trim()).equals("")) {
website = "";
} else {
website = "http://" + website;
}
}
// set Entity
if (entity != "") {
boolean entityFlag = entityList.containsKey(entity);
if (entityFlag) {
entId = Integer.parseInt((String) entityList.get(entity));
} else {
dl.setSql("contact.addentity");
dl.setString(1, entityExternalID);
dl.setString(2, entity);
dl.setInt(3, sourceEn);
dl.setInt(4, 0);
dl.setInt(5, listid);
dl.setInt(6, indvID);
dl.setInt(7, indvID);
dl.setInt(8, user);
dl.setInt(9, groupID);
dl.executeUpdate();
entId = dl.getAutoGeneratedKey();
dl.clearParameters();
// apply the logged-in user's default privileges to this record
//remoteAuth.saveCurrentDefaultPermission("Entity", entId, indvID);
if (!newEntityList.contains(entId+"")) {
newEntityList.add(entId+"");
}
//Add the new Entity to the EntityList
entityList.put(entity, entId + "");
}
boolean addressFlag = primaryContactList.containsKey(entId +"");
if (!addressFlag) {
String Contact = (String) primaryContactList.get(entId + "");
if (Contact == null) {
entityPrimaryFlag = true;
}
if ((Contact != null) && Contact.equals("NO")) {
entityPrimaryFlag = true;
}
}
if ((CustomEntList != null) && (CustomEntList.size() > 0)) {
Iterator it = CustomEntList.iterator();
while (it.hasNext()) {
DDNameValue ddname = (DDNameValue) it.next();
String id = ddname.getName();
String type = null;
StringTokenizer st = new StringTokenizer(id, "*");
while (st.hasMoreTokens()) {
id = (String) st.nextToken();
type = (String) st.nextToken();
}
String name = ddname.getStrid();
String customEntityValue = (String) hCols.get(name);
String customName = name.substring(0, name.indexOf("("));
if (type != null) {
//Scalar Value
if (type.equals("SCALAR")) {
if (customEntityValue != null) {
batchQuery.add("insert into customfieldscalar (customfieldid,recordid,value) values (" + id + "," + entId + ",'" + customEntityValue + "')");
}
}
//Multiple Value
if (type.equals("MULTIPLE")) {
int indexName = name.indexOf("(");
if (indexName > 0) {
customEntityValue = customEntityValue + "*" + name.substring(0, indexName);
}
boolean customFlag = CustomFieldValues.containsKey(customEntityValue);
if (customFlag) {
String fieldId = (String) CustomFieldValues.get(customEntityValue);
String valueId = null;
st = null;
st = new StringTokenizer(fieldId, "*");
while (st.hasMoreTokens()) {
valueId = (String) st.nextToken();
fieldId = (String) st.nextToken();
}
if (valueId != null) {
if (fieldId.equals(id)) {
batchQuery.add( "insert into customfieldmultiple (customfieldid,recordid,valueid) values (" + id + "," + entId + "," + valueId + ")");
}
}
}
}
}
}
}
}
int individualID = 0;
// create Individual
dl.setSql("contact.createindividual");
dl.setInt(1, entId);
dl.setString(2, fName);
dl.setString(3, lName);
dl.setString(4, title);
dl.setInt(5, indvID);
if (entityPrimaryFlag) {
dl.setString(6, "YES");
} else {
dl.setString(6, "NO");
}
dl.setString(7, mName);
dl.setInt(8, sourceId);
dl.setString(9, individualExternalID);
dl.setInt(10, listid);
dl.setInt(11, indvID);
try {
dl.executeUpdate();
individualID = dl.getAutoGeneratedKey();
dl.clearParameters();
// apply the logged-in user's default privileges to this record
//remoteAuth.saveCurrentDefaultPermission("Individual", individualID, indvID);
if (!newIndividualList.contains(individualID+"")) {
newIndividualList.add(individualID+"");
}
if (entId != 0) {
primaryContactList.put(entId + "", "YES");
}
if (individualID == 0) {
errMsg = errMsg + "Failed to create Individual,";
errCounter++;
}
} catch (Exception ex) {
errMsg = errMsg + "Failed to create Individual,";
errCounter++;
ex.printStackTrace();
throw new CreateException();
} finally {
dl.clearParameters();
}
try {
if (! street1.equals("") || ! street2.equals("") || ! city.equals("") ||
! state.equals("") || ! zip.equals("") || ! country.equals("") ||
! website.equals("")) {
dl.setSql("contact.addaddress");
dl.setInt(1, 1);
dl.setString(2, street1);
dl.setString(3, street2);
dl.setString(4, city);
dl.setString(5, state);
dl.setString(6, zip);
dl.setString(7, country);
dl.setString(8, website);
dl.setInt(9, 0);
dl.executeUpdate();
int adrId = dl.getAutoGeneratedKey();
dl.clearParameters();
batchQuery.add("insert into addressrelate (Address, ContactType, Contact, AddressType, IsPrimary) values (" + adrId + ", 2, " + individualID + ", 1, 'YES')");
if (entityPrimaryFlag) {
batchQuery.add("insert into addressrelate (Address, ContactType, Contact, AddressType, IsPrimary) values (" + adrId + ", 1, " + entId + ", 1, 'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
// set workPhone
if ((workPhone != null) && (!workPhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_WORK);
dl.setString(2, workPhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Work");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate (MOCID, ContactType, ContactID, isPrimary) values (" + mocId + ", 2, " + individualID + ", 'YES')");
if (entityPrimaryFlag) {
batchQuery.add("INSERT INTO mocrelate (MOCID, ContactType, ContactID, isPrimary) values (" + mocId + ", 1, " + entId + ", 'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set homePhone
if ((homePhone != null) && (!homePhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_HOME);
dl.setString(2, homePhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Home");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate (MOCID, ContactType, ContactID, isPrimary) values (" + mocId + ", 2, " + individualID + ", 'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate (MOCID, ContactType, ContactID, isPrimary) values (" + mocId + ", 1, " + entId + ", 'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set faxPhone
if ((faxPhone != null) && (!faxPhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_FAX);
dl.setString(2, faxPhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Fax");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0)
{
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set otherPhone
if ((otherPhone != null) && (!otherPhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_OTHER);
dl.setString(2, otherPhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Other");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set mainPhone
if ((mainPhone != null) && (!mainPhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_MAIN);
dl.setString(2, mainPhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Main");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set pagerPhone
if ((pagerPhone != null) && (!pagerPhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_PAGER);
dl.setString(2, pagerPhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Pager");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set mobilePhone
if ((mobilePhone != null) && (!mobilePhone.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_MOBILE);
dl.setString(2, mobilePhone);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Mobile");
dl.setString(5, null); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
// set Email
if ((email != null) && (!email.equals(""))) {
try {
dl.setSql("contact.addmoc");
dl.setInt(1, Constants.MOC_EMAIL);
dl.setString(2, email);
dl.setString(3, ""); //moc.getNote()
dl.setString(4, "Email");
dl.setString(5, ""); //moc.getMocOrder()
dl.executeUpdate();
int mocId = dl.getAutoGeneratedKey();
dl.clearParameters();
if (mocId != 0) {
batchQuery.add("insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",2," + individualID + ",'YES')");
if (entityPrimaryFlag) {
batchQuery.add( "insert into mocrelate(MOCID,ContactType," + "ContactID,isPrimary) values(" + mocId + ",1," + entId + ",'YES')");
}
}
} catch (Exception e) {
logger.error("[Exception] ListEJB.getImportList: ", e);
}
}
if ((CustomIndList != null) && (CustomIndList.size() > 0)) {
Iterator it = CustomIndList.iterator();
while (it.hasNext()) {
DDNameValue ddname = (DDNameValue) it.next();
String id = ddname.getName();
String type = null;
StringTokenizer st = new StringTokenizer(id, "*");
while (st.hasMoreTokens()) {
id = (String) st.nextToken();
type = (String) st.nextToken();
}
String name = ddname.getStrid();
String customIndividualName = (String) hCols.get(name);
if (type != null) {
//Scalar Value
if (type.equals("SCALAR")) {