📄 leadeventprocessor.java
字号:
Debug.logVerbose("Setting leadOwnerId to " +
userInfo.getPartyId(), module);
leadGV.set("leadOwnerId", userInfo.getPartyId());
}
// Set the assigned date.
leadGV.set("assignedDate", now);
// Set the account ID if it is empty.
String accountId = leadGV.getString("accountId");
if ((accountId == null) || accountId.equals("")) {
leadGV.set("accountId", userInfo.getAccountId());
}
String ownerId = leadGV.getString("leadOwnerId");
//add the team access info
SecurityWrapper.addRoleInformation(dataMatrix, 0, userInfo, ownerId,
"Lead", leadId, delegator);
String statusId = leadGV.getString("statusId");
if (statusId == null) {
statusId = "10";
leadGV.set("statusId", statusId);
}
if (leadGV.get("activeFlag") == null) {
leadGV.set("activeFlag", new Boolean(true));
}
if (leadGV.get("validatedFlag") == null) {
leadGV.set("validatedFlag", new Boolean(true));
}
if (addressGV.get("country") == null) {
addressGV.set("country", "USA");
}
if (statusId.equals("50")) {
// Status is "converted". Set the converted date.
leadGV.set("convertedDate", now);
}
return STATUS_CONTINUE;
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param entityNameList
* @param delegator
* @param dataMatrix
*
* @return
*/
protected int postCreate(UserInfo userInfo, List entityNameList,
GenericDelegator delegator, DataMatrix dataMatrix) {
// Get the empty generic values.
GenericValue leadGV = null;
GenericValue addressGV = null;
GenericValue partyGV = null;
try {
leadGV = dataMatrix.getCurrentBuffer().getGenericValue(0, "Lead",
true);
addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
"Address", false);
partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0, "Party",
false);
} catch (GenericEntityException e) {
Debug.logError("Error getting generic value: " + e.toString(), module);
return STATUS_ERROR;
}
// Set default values on the new record so they will be displayed for the user to see before saving.
// Lead owner ID
Debug.logVerbose("Setting leadOwnerId to " + userInfo.getPartyId(), module);
leadGV.set("leadOwnerId", userInfo.getPartyId());
leadGV.set("statusId", "10");
// Active Flag
leadGV.set("activeFlag", new Boolean(true));
leadGV.set("validatedFlag", new Boolean(true));
// Country
addressGV.set("country", "USA");
// Refresh the cache in the delegator so that dropdowns will show the new lead
delegator.getAndCache().clear();
return STATUS_CONTINUE;
}
/** event handler for quick insert screen */
public boolean QuickInsert(UserInfo userInfo, GenericDelegator delegator,
String firstName, String lastName, String title, String companyName,
String businessPhone, String mailingAddress, String city, String state,
String zip, String country, String statusId, String leadTypeId,
String activeFlag, String validatedFlag) {
GenericValue leadGV = new GenericValue(delegator.getModelEntity("Lead"));
leadGV.setDelegator(delegator);
GenericValue addressGV = new GenericValue(delegator.getModelEntity(
"Address"));
addressGV.setDelegator(delegator);
GenericValue partyGV = new GenericValue(delegator.getModelEntity(
"Party"));
partyGV.setDelegator(delegator);
leadGV.set("firstName", firstName);
leadGV.set("lastName", lastName);
leadGV.set("title", title);
leadGV.set("companyName", companyName);
leadGV.set("businessPhone", businessPhone);
addressGV.set("mailingAddress", mailingAddress);
addressGV.set("isPrimary", "Y");
addressGV.set("city", city);
addressGV.set("state", state);
addressGV.set("zip", zip);
addressGV.set("country", country);
leadGV.set("statusId", statusId);
leadGV.set("leadTypeId", leadTypeId);
leadGV.set("activeFlag",
activeFlag.toUpperCase().equals("Y") ? new Boolean(true)
: new Boolean(false));
leadGV.set("validatedFlag",
validatedFlag.toUpperCase().equals("Y") ? new Boolean(true)
: new Boolean(false));
// call the Name processor to split full name into first, last, etc or to combine first/last to full name
ContactEventProcessor.setNameFields( leadGV );
DataMatrix dataMatrix = new DataMatrix(delegator, new Vector());
dataMatrix.getCurrentBuffer().addContentsRow(new Vector());
dataMatrix.addEntity("Lead", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(leadGV);
dataMatrix.addEntity("Address", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(addressGV);
dataMatrix.addEntity("Party", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(partyGV);
if (preInsert(userInfo, delegator, dataMatrix) != STATUS_CONTINUE) {
return false;
}
try {
delegator.storeAll((List) dataMatrix.getCurrentBuffer()
.getContentsRow(0));
} catch (GenericEntityException e2) {
Debug.logError("Error saving new lead: " +
e2.getLocalizedMessage(), module);
return false;
}
if (postInsert(userInfo, delegator, dataMatrix) != STATUS_CONTINUE) {
return false;
}
return true;
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
* @param originatingEntityName
* @param entityGV
*
* @return
*/
public int deleteAllRelated(UserInfo userInfo, GenericDelegator delegator,
String originatingEntityName, GenericValue entityGV) {
int status = STATUS_CONTINUE;
// Delete related Addresses.
status = deleteOneRelated(userInfo, delegator, entityGV, "", "Address",
originatingEntityName, new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related Parties.
status = deleteOneRelated(userInfo, delegator, entityGV, "", "Party",
originatingEntityName, new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related FileAttachments. (Note: This must happen before the LeadFiles are deleted.)
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"FileAttachment", originatingEntityName,
new AbstractAttachmentEP());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related LeadFiles. (Note: This must happen after the FileAttachments are deleted.)
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"LeadFile", originatingEntityName, new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
return STATUS_CONTINUE;
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
* @param entityGV
* @param relationTitle
* @param relatedEntityName
*
* @return
*/
public List findOneRelated(UserInfo userInfo, GenericDelegator delegator,
GenericValue entityGV, String relationTitle, String relatedEntityName) {
// Find instances of an entity related to the current entity so the instances can be deleted.
if (relatedEntityName.equals("FileAttachment")) {
// Finding related FileAttachment records. Need special processing because the relationship cannot be
// defined in the sfa-config.xml file.
// Get all the related LeadFile records using the generic version of findOneRelated.
List leadFileGVL = super.findOneRelated(userInfo, delegator,
entityGV, "", "LeadFile");
// Make a List of FileAttachments tied to the identified LeadFiles.
List fileAttachmenGVL = new LinkedList();
Iterator leadFileGVI = leadFileGVL.iterator();
while (leadFileGVI.hasNext()) {
GenericValue leadFileGV = (GenericValue) leadFileGVI.next();
try {
GenericValue fileAttachmentGV = delegator.getRelatedOne("FileAttachment",
leadFileGV);
if (fileAttachmentGV != null) {
fileAttachmenGVL.add(fileAttachmentGV);
}
} catch (GenericEntityException e) {
Debug.logError("Error retrieving FileAttachment record: " +
e.getLocalizedMessage(), module);
}
}
Debug.logVerbose("End - FileAttachment", module);
return fileAttachmenGVL;
} else {
// Not finding EntityAccess or FileAttachment records. Just use the standard processing using relations.
return super.findOneRelated(userInfo, delegator, entityGV,
relationTitle, relatedEntityName);
}
}
/**
* DOCUMENT ME!
*
* @param mainGV
* @param relatedSearchClause
* @param outGVV
* @param userInfo
* @param delegator
*
* @return
*/
protected GenericValue retrieveOneRelatedGV(GenericValue mainGV,
UIScreenSectionEntity relatedSearchClause, Vector outGVV, UserInfo userInfo,
GenericDelegator delegator) {
String relationRelEntityName = (String) relatedSearchClause.getEntityName();
if (relationRelEntityName.equals("Address")) {
// Special processing for the Address record since it can't be retrieved with a relationship
// defined in the sfa-config.xml file.
// Get lead ID from the Lead record.
String leadId = mainGV.getString("leadId");
HashMap addressFindMap = new HashMap();
addressFindMap.put("addressOwnerId", leadId);
addressFindMap.put("isPrimary", "Y");
GenericValue addressGV = null;
try {
List addressGVL = delegator.findByAnd("Address", addressFindMap);
Iterator addressGVI = addressGVL.iterator();
if (addressGVI.hasNext()) {
// Address record was found.
addressGV = (GenericValue) addressGVI.next();
Debug.logVerbose("Address was found:" +
addressGV.toString(), module);
} else {
// Address record was not found. Allow generic event processor to create an empty one.
Debug.logVerbose("Address was not found.", module);
}
return addressGV;
} catch (GenericEntityException e) {
Debug.logError("An error occurred while searching for " +
"the address record for the Lead: " +
e.getLocalizedMessage(), module);
return addressGV;
}
} else {
// Retrieve all other related entities the regular way.
return super.retrieveOneRelatedGV(mainGV, relatedSearchClause,
outGVV, userInfo, delegator);
}
}
/**
* Add entity clauses for one related entity. This will join related tables to the query
* during a retrieve so query values can be entered that are in related entities.
* <P>
* This version overrides the ancestor to handle the Account entity, which
* has no relation defined.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
* @param relationTitle Relation title
* @param relatedEntityName Name of related entity
* @param primaryEntityName Name of the primary entity
* @param primaryME ModelEntity object for the primary entity
* @param queryInfo criteria to be used in search
*/
public void addOneRelationClause(GenericDelegator delegator,
String relationTitle, String relatedAndFields, String relatedEntityName,
String primaryEntityName, ModelEntity primaryME, boolean isOuterJoin, QueryInfo queryInfo)
throws GenericEntityException {
if (relatedEntityName.equals("Address")) {
// Adding entity clauses for the Address entity. Need to build it manually.
// Join the address owner ID field
Debug.logVerbose("[addOneRelationClause] Added to entityClauses: " +
"Lead" + ", " + "Address" + ", " + "leadId" + ", " +
"addressOwnerId", module);
queryInfo.addJoin("Lead", "Address", Boolean.valueOf(isOuterJoin), "leadId", "addressOwnerId");
if ( isOuterJoin )
{
queryInfo.addAlias("Address", "isPrimary", "isPrimary");
queryInfo.addAlias("Address", "addressId", "addressId");
queryInfo.addCondition( new EntityConditionList( UtilMisc.toList( new EntityExpr("isPrimary", EntityOperator.EQUALS, "Y"),
new EntityExpr("addressId", EntityOperator.EQUALS, null)), EntityOperator.OR));
}
else
queryInfo.addCondition("Address", "isPrimary", EntityOperator.EQUALS, "Y");
} else {
// Use the parent script for all other related entities.
super.addOneRelationClause(delegator, relationTitle, relatedAndFields,
relatedEntityName, primaryEntityName, primaryME, isOuterJoin, queryInfo);
}
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
*
* @return
*/
public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo,
GenericDelegator delegator) {
return new SecurityLinkInfo("Lead", "leadId", false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -