UserObject userobject = (UserObject)session.getAttribute("userobject");
ModuleFieldRightMatrix mfrmx = ((UserObject)session.getAttribute("userobject")).getUserPref().getModuleAuthorizationMatrix();
HashMap entityRights = mfrmx.getFieldRights("Entity");
ContactFacadeHome contactFacadeHome = (ContactFacadeHome)CVUtility.getHomeObject("com.centraview.contact.contactfacade.ContactFacadeHome", "ContactFacade");
ContactFacade contactFacadeRemote = (ContactFacade)contactFacadeHome.create();
// Here's hoping the EntityVOX is only used from the struts layer.
contactFacadeRemote.setDataSource(dataSource);
int entityId = entityIdForm.intValue();
EntityVO entityVOReference = null;
if (entityId > 0) {
entityVOReference = contactFacadeRemote.getEntity(entityIdForm.intValue());
} else {
entityVOReference = new EntityVO();
entityVOReference.setContactID(entityId);
}
// populate this VO completely from the Database.
entityVOReference.setContacyType(1);
this.setVO(entityVOReference);
if (CVUtility.updateFieldPermitted(entityRights, "name")) {
this.setName((String)dynaForm.get("entityName"));
}
if (CVUtility.updateFieldPermitted(entityRights, "id2")) {
this.setExternalID((String)dynaForm.get("id2"));
}
AddressVO primaryAddress = this.getPrimaryAddress();
if (CVUtility.updateFieldPermitted(entityRights, "address")) {
primaryAddress.setStreet1((String)dynaForm.get("street1"));
primaryAddress.setStreet2((String)dynaForm.get("street2"));
primaryAddress.setCity((String)dynaForm.get("city"));
primaryAddress.setStateName((String)dynaForm.get("state"));
primaryAddress.setZip((String)dynaForm.get("zip"));
primaryAddress.setCountryName((String)dynaForm.get("country"));
String webSiteForm = (dynaForm.get("website") == null || dynaForm.get("website") == null) ? "" : (String)dynaForm.get("website");
String webSite = "";
if (webSiteForm.matches("^https?://.+")) {
webSite = webSiteForm;
} else if (webSiteForm.trim().length() > 0) {
webSite = "http://" + webSiteForm;
}
primaryAddress.setWebsite(webSite);
Integer addressId = dynaForm.get("addressId") == null ? new Integer(-1) : (Integer)dynaForm.get("addressId");
primaryAddress.setAddressID(addressId.intValue());
primaryAddress.setIsPrimary("YES");
if (!primaryAddress.isEmpty()) {
this.setPrimaryAddress(primaryAddress);
}
}
if (CVUtility.updateFieldPermitted(entityRights, "source")) {
Integer sourceIdInteger = (Integer)dynaForm.get("sourceId");
int sourceId = sourceIdInteger == null ? 0 : sourceIdInteger.intValue();
this.setSource(sourceId);
this.setSourceName((String)dynaForm.get("sourceName"));
}
if (CVUtility.updateFieldPermitted(entityRights, "acctmanager")) {
this.setAccManager(((Integer)dynaForm.get("accountManagerId")).intValue());
this.setAcctMgrName((String)dynaForm.get("accountManagerName"));
}
if (CVUtility.updateFieldPermitted(entityRights, "acctteam")) {
this.setAccTeam(((Integer)dynaForm.get("accountTeamId")).intValue());
this.setAcctTeamName((String)dynaForm.get("accountTeamName"));
}
String pcFName = dynaForm.get("pcFirstName") == null ? "" : (String)dynaForm.get("pcFirstName");
String pcMName = dynaForm.get("pcMiddleInitial") == null ? "" : (String)dynaForm.get("pcMiddleInitial");
String pcLName = dynaForm.get("pcLastName") == null ? "" : (String)dynaForm.get("pcLastName");
String pcTitle = dynaForm.get("pcTitle") == null ? "" : (String)dynaForm.get("pcTitle");
IndividualVO individualVO = null;
int individualId = dynaForm.get("pcIndividualId") == null ? 0 : ((Integer)dynaForm.get("pcIndividualId")).intValue();
if (individualId != 0) {
individualVO = contactFacadeRemote.getIndividual(individualId);
// In certain cases (when the individual was imported via marketing list)
// The individual and the Entity share the same (exact) Address Therefore
// If that is the case, I must make sure the IndividualVO address is updated also
// otherwise the crapiness of the Entity and Individual EJB interaction. will
// cause a condition, which always reverts the common address to the old one