ContactHelperLocalHome homeContact = (ContactHelperLocalHome)ic.lookup("local/ContactHelper");
ContactHelperLocal remoteContact = homeContact.create();
remoteContact.setDataSource(this.dataSource);
CommonHelperLocalHome homeCommon = (CommonHelperLocalHome)ic.lookup("local/CommonHelper");
CommonHelperLocal remoteCommon = homeCommon.create();
remoteCommon.setDataSource(this.dataSource);
HashMap sourceList = remoteCommon.getSourceList();
Vector groupList = remoteContact.getGroups();
HashMap entityList = remoteContact.getEntityList(listid);
HashMap employeeList = remoteContact.getEmployeeList();
//remoteCommon = null;
homeCommon = null;
remoteContact = null;
homeContact = null;
// Collect all the CustomfieldValue
CustomFieldLocalHome homeCustomField = (CustomFieldLocalHome)ic.lookup("local/CustomField");
CustomFieldLocal remoteCustomField = homeCustomField.create();
remoteCustomField.setDataSource(this.dataSource);
HashMap CustomFieldValues = remoteCustomField.getCustomFieldValue();
homeCustomField = null;
remoteCustomField = null;
ArrayList newEntityList = new ArrayList();
ArrayList newIndividualList = new ArrayList();
int errCounter = 0;
//initalize the cvDal
CVDal dl = new CVDal(dataSource);
dl.setSqlQuery("SELECT a.PrimaryContact ,b.EntityId FROM individual a, "
+ "entity b WHERE a.Entity=b.EntityId AND PrimaryContact='YES' "
+ "AND a.list=" + listid);
Collection col = dl.executeQuery();
dl.clearParameters();
HashMap primaryContactList = new HashMap();
if (col != null) {
Iterator it = col.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
String name = (String) hm.get("PrimaryContact");
int id = ((Long) hm.get("EntityId")).intValue();
primaryContactList.put(id + "", name.trim());
}
}
int count = importList.size();
ArrayList batchQuery = new ArrayList();
int i = 0;
while (i < importList.size()) {
HashMap hCols = (HashMap) importList.get(0);
line = (String) hCols.get("Line");
String showLine = line;
if (line != null && line.length() >25) {
showLine = line.substring(0, 25);
}
entityPrimaryFlag = false;
errMsg = "";
if (hCols.size() == 0) {
errMsg = "Delimitor doesn't Match Up!,";
errCounter++;
} else {
fName = (String) hCols.get("First Name");
lName = (String) hCols.get("Last Name");
mName = (String) hCols.get("Middle Name");
entity = (String) hCols.get("Entity Name");
manager = (String) hCols.get("Account Manager");
group = (String) hCols.get("Account Team");
street1 = (String) hCols.get("Street1");
street2 = (String) hCols.get("Street2");
city = (String) hCols.get("City");
state = (String) hCols.get("State");
country = (String) hCols.get("Country");
zip = (String) hCols.get("Zipcode");
title = (String) hCols.get("Title");
homePhone = (String) hCols.get("Home Phone");
faxPhone = (String) hCols.get("Fax Phone");
mainPhone = (String) hCols.get("Main Phone");
mobilePhone = (String) hCols.get("Mobile Phone");
otherPhone = (String) hCols.get("Other Phone");
pagerPhone = (String) hCols.get("Pager Phone");
workPhone = (String) hCols.get("Work Phone");
email = (String) hCols.get("Email");
entityExternalID = (String) hCols.get("ExternalID (Entity)");
individualExternalID = (String) hCols.get("ExternalID (Individual)");
sourceIndividual = (String) hCols.get("Source (Individual)");
sourceEntity = (String) hCols.get("Source (Entity)");
website = (String) hCols.get("Website");
if (fName == null) {
fName = "";
}
if (lName == null) {
lName = "";
}
if (manager == null) {
manager = "";
}
if (group == null) {
group = "";
}
if (mName == null) {
mName = "";
}
if (entity == null) {
entity = "";
}
if (street1 == null) {
street1 = "";
}
if (street2 == null) {
street2 = "";
}
if (city == null) {
city = "";
}
if (state == null) {
state = "";
}
if (country == null) {
country = "";
}
if (zip == null) {
zip = "";
}
if (title == null) {
title = "";
}
if (homePhone == null) {
homePhone = "";
}
if (faxPhone == null) {
faxPhone = "";
}
if (mainPhone == null) {
mainPhone = "";
}
if (mobilePhone == null) {
mobilePhone = "";
}
if (otherPhone == null) {
otherPhone = "";
}
if (pagerPhone == null) {
pagerPhone = "";
}
if (workPhone == null) {
workPhone = "";
}
if (email == null) {
email = "";
}
if (entityExternalID == null) {
entityExternalID = "";
}
if (individualExternalID == null) {
individualExternalID = "";
}
if (sourceIndividual == null) {
sourceIndividual = "";
}
if (sourceEntity == null) {
sourceEntity = "";
}
if (website == null) {
website = "";
}
if ((fName.equals("")) && (lName.equals("")) && (website.equals("")) &&
(manager.equals("")) && (group.equals("")) && (mName.equals("")) &&
(entity.equals("")) && (street1.equals("")) &&
(street2.equals("")) && (city.equals("")) && (state.equals("")) &&
(country.equals("")) && (zip.equals("")) && (title.equals("")) &&
(homePhone.equals("")) && (faxPhone.equals("")) &&
(mainPhone.equals("")) && (mobilePhone.equals("")) &&
(otherPhone.equals("")) && (pagerPhone.equals("")) &&
(workPhone.equals("")) && (email.equals("")) &&
(entityExternalID.equals("")) &&
(individualExternalID.equals("")) &&
(sourceIndividual.equals("")) && (sourceEntity.equals("")))
{
errMsg = errMsg + "Delimitor doesn't Match Up!,";
errCounter++;
} else {
if (entity.equals("") || ((fName.equals("")) && (lName.equals("")))) {
if (entity.equals("")) {
errMsg = errMsg + "Entity is a Required Field,";
}
if (fName.equals("")) {
errMsg = errMsg + "First Name is a Required Field,";
}
if (lName.equals("")) {
errMsg = errMsg + "Last Name is a Required Field,";
}
errCounter++;
} else {
boolean flagInsert = true;
if (! manager.equals("")) {
int user = 0;
boolean employeeFlag = employeeList.containsKey(manager);
if (employeeFlag) {
user = Integer.parseInt((String) employeeList.get(manager));
}
if (user == 0) {
errMsg = errMsg + "Account Manager \"" + manager + "\" not found in Employee List,";
flagInsert = false;
}
}
if (! group.equals("")) {
// 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();
}
}
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();
}
}