individualVO.setMOC(syncUtils.createNewPhoneMoc(mobilePhone, mobilePhoneExt, "Mobile" , Constants.MOC_MOBILE));
}
// might as well create the EJB connections now...
ContactFacadeHome cfh = (ContactFacadeHome)CVUtility.getHomeObject("com.centraview.contact.contactfacade.ContactFacadeHome","ContactFacade");
ContactFacade cfremote = (ContactFacade)cfh.create();
cfremote.setDataSource(dataSource);
SyncFacadeHome syncHome = (SyncFacadeHome)CVUtility.getHomeObject("com.centraview.syncfacade.SyncFacadeHome", "SyncFacade");
com.centraview.syncfacade.SyncFacade sfremote = (com.centraview.syncfacade.SyncFacade)syncHome.create();
sfremote.setDataSource(dataSource);
// first, we need to get the entityID based on the CompanyName
// passed into the form. If the entity name doesn't match something
// in the database, then set a flag to create a new entity.
int finalEntityID = 0;
boolean createNewEntity = false;
if (companyName != null && (! companyName.equals("")))
{
finalEntityID = sfremote.findCompanyNameMatch(companyName, individualID);
if (finalEntityID == 0)
{
createNewEntity = true;
}
} // end if (companyName != null && (! companyName.equals("")))
// now that we've got all the Individual's info set up properly in
// the appropriate VO objects, let's create an Entity if necessary
String primaryContact = "Yes"; // gets set to no if we're updating an existing entity
if (createNewEntity)
{
// in this case, we didn't find a match to our entity name in the
// database, so we'll create a new entity with any form information
EntityVO newEntity = new EntityVO();
newEntity.setContactType(1); // contact type 1 = Entity
newEntity.setName(companyName);
newEntity.setSourceName((String)contactForm.get("entitySource"));
newEntity.setExternalID((String)contactForm.get("entityID2"));
// Entity Address information
String eStreet1 = (String)contactForm.get("entityStreet1");
String eStreet2 = (String)contactForm.get("entityStreet2");
String eCity = (String)contactForm.get("entityCity");
String eState = (String)contactForm.get("entityState");
String eZipCode = (String)contactForm.get("entityZip");
String eCountry = (String)contactForm.get("entityCountry");
// only create an Address VO if ONE or MORE fields are filled in
if ((eStreet1 != null && eStreet1.length() > 0) || (eStreet2 != null && eStreet2.length() > 0) ||
(eCity != null && eCity.length() > 0) || (eState != null && eState.length() > 0) ||
(eZipCode != null && eZipCode.length() > 0) || (eCountry != null && eCountry.length() > 0))
{
AddressVO ePrimaryAddress = new AddressVO();
ePrimaryAddress.setIsPrimary("YES");
ePrimaryAddress.setStreet1(eStreet1);
ePrimaryAddress.setStreet2(eStreet2);
ePrimaryAddress.setCity(eCity);
ePrimaryAddress.setStateName(eState);
ePrimaryAddress.setZip(eZipCode);
ePrimaryAddress.setCountryName(eCountry);
newEntity.setPrimaryAddress(ePrimaryAddress);
}else{
// if no entity address information was given, use individual address
newEntity.setPrimaryAddress(primaryAddress);
}
// save email address
String eEmail = (String)contactForm.get("entityEmail");
if (eEmail != null && ! eEmail.equals(""))
{
MethodOfContactVO eEmailVO = new MethodOfContactVO();
eEmailVO.setContent(eEmail);
eEmailVO.setMocType(1); // hardcoded to "Email" type
eEmailVO.setIsPrimary("YES"); // always set as the primary email address
newEntity.setMOC(eEmailVO);
}
// set workPhone
String eWorkPhone = (String)contactForm.get("entityWorkPhone");
if (eWorkPhone != null && ! eWorkPhone.equals(""))
{
String eWorkPhoneExt = (String)contactForm.get("entityWorkPhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eWorkPhone, eWorkPhoneExt, "Work", Constants.MOC_WORK)); // (content, ext, syncAs, mocType)
}
// set homePhone
String eHomePhone = (String)contactForm.get("entityHomePhone");
if (eHomePhone != null && ! eHomePhone.equals(""))
{
String eHomePhoneExt = (String)contactForm.get("entityHomePhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eHomePhone, eHomePhoneExt, "Home", Constants.MOC_HOME)); // (content, ext, syncAs, mocType)
}
// set FaxPhone
String eFaxPhone = (String)contactForm.get("entityFaxPhone");
if (eFaxPhone != null && ! eFaxPhone.equals(""))
{
String eFaxPhoneExt = (String)contactForm.get("entityFaxPhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eFaxPhone, eFaxPhoneExt, "Fax", Constants.MOC_FAX)); // (content, ext, syncAs, mocType)
}
// set OtherPhone
String eOtherPhone = (String)contactForm.get("entityOtherPhone");
if (eOtherPhone != null && ! eOtherPhone.equals(""))
{
String eOtherPhoneExt = (String)contactForm.get("entityOtherPhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eOtherPhone, eOtherPhoneExt, "Other", Constants.MOC_OTHER)); // (content, ext, syncAs, mocType)
}
// set MainPhone
String eMainPhone = (String)contactForm.get("entityMainPhone");
if (eMainPhone != null && ! eMainPhone.equals(""))
{
String eMainPhoneExt = (String)contactForm.get("entityMainPhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eMainPhone, eMainPhoneExt, "Main", Constants.MOC_MAIN)); // (content, ext, syncAs, mocType)
}
// set PagerPhone
String ePagerPhone = (String)contactForm.get("entityPagerPhone");
if (ePagerPhone != null && ! ePagerPhone.equals(""))
{
String ePagerPhoneExt = (String)contactForm.get("entityPagerPhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(ePagerPhone, ePagerPhoneExt, "Pager", Constants.MOC_PAGER)); // (content, ext, syncAs, mocType)
}
// set MobilePhone
String eMobilePhone = (String)contactForm.get("entityMobilePhone");
if (eMobilePhone != null && ! eMobilePhone.equals(""))
{
String eMobilePhoneExt = (String)contactForm.get("entityMobilePhoneExt");
newEntity.setMOC(syncUtils.createNewPhoneMoc(eMobilePhone, eMobilePhoneExt, "Mobile", Constants.MOC_MOBILE)); // (content, ext, syncAs, mocType)
}
// custom fields
this.addCustomFields(newEntity, mailRemote.getValidFields("Entity"), contactForm);
int newEntityID = cfremote.createEntity(newEntity, individualID);
finalEntityID = newEntityID;
}else{
primaryContact = "No";
// in this block, we're updating an existing entity
// USE finalEntityID to update the existing entity
// TODO: write code for updating existing entity
}
// custom fields...
this.addCustomFields(individualVO, mailRemote.getValidFields("Individual"), contactForm);
// create the individual record via the ContactFacade
individualVO.setEntityID(finalEntityID);
individualVO.setIsPrimaryContact(primaryContact);
newIndividualID = cfremote.createIndividual(individualVO, individualID);
if (newIndividualID > 0)
{
// we need to make the IndividualList dirty, so that the next time
// it is viewed, it is refreshed and contains the record we just added