📄 contacteventprocessor.java
字号:
partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0, "Party",
false);
userLoginGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
"UserLogin", false);
} catch (GenericEntityException e) {
Debug.logError(
"[ContactEventProcessor.postCreate] 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.
// Contact owner ID
contactGV.set("contactOwnerId", userInfo.getPartyId());
// Status
contactGV.set("statusId", "A");
// Contact Type
contactGV.set("contactTypeId", "regular");
// Country
addressGV.set("country", "USA");
// Refresh the cache in the delegator so that dropdowns will show the new contact
delegator.getAndCache().clear();
return STATUS_CONTINUE;
}
/**
* 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 ActivityContacts.
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"ActivityContact", originatingEntityName,
new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// 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 UserLogins.
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"UserLogin", originatingEntityName, new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related OpportunityContacts.
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"OpportunityContact", originatingEntityName,
new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related FileAttachments. (Note: This must happen before the ContactFiles are deleted.)
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"FileAttachment", originatingEntityName,
new AbstractAttachmentEP());
if (status != STATUS_CONTINUE) {
return status;
}
// Delete related ContactFiles. (Note: This must happen after the FileAttachments are deleted.)
status = deleteOneRelated(userInfo, delegator, entityGV, "",
"ContactFile", originatingEntityName,
new GenericEventProcessor());
if (status != STATUS_CONTINUE) {
return status;
}
// Find any activities whose contactId field has the current contactId in it, and change the contactId to null.
List activityGVL = super.findOneRelated(userInfo, delegator, entityGV,
"", "Activity");
Iterator activityGVI = activityGVL.iterator();
while (activityGVI.hasNext()) {
GenericValue activityGV = (GenericValue) activityGVI.next();
String activityId = activityGV.getString("activityId");
activityGV.set("contactId", null);
try {
activityGV.store();
} catch (GenericEntityException e) {
Debug.logError(
"[ContactEventProcessor.deleteAllRelated] Error clearing the contact ID field on " +
"a related activity during delete of a contact: " +
e.getLocalizedMessage(), module);
}
}
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 ContactFile records using the generic version of findOneRelated.
List contactFileGVL = super.findOneRelated(userInfo, delegator,
entityGV, "", "ContactFile");
// Make a List of FileAttachments tied to the identified ContactFiles.
List fileAttachmenGVL = new LinkedList();
Iterator contactFileGVI = contactFileGVL.iterator();
while (contactFileGVI.hasNext()) {
GenericValue contactFileGV = (GenericValue) contactFileGVI.next();
try {
GenericValue fileAttachmentGV = delegator.getRelatedOne("FileAttachment",
contactFileGV);
if (fileAttachmentGV != null) {
fileAttachmenGVL.add(fileAttachmentGV);
}
} catch (GenericEntityException e) {
Debug.logError(
"[ContactEventProcessor.findOneRelated] Error retrieving FileAttachment record: " +
e.getLocalizedMessage(), 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 Contact ID from the Contact record.
String contactId = mainGV.getString("contactId");
HashMap addressFindMap = new HashMap();
addressFindMap.put("addressOwnerId", contactId);
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();
} else {
// Address record was not found. Allow generic event processor to create an empty one.
}
return addressGV;
} catch (GenericEntityException e) {
Debug.logError(
"[ContactEventProcessor.retrieveOneRelatedGV] An error occurred while searching for " +
"the address record for the Contact: " +
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
queryInfo.addJoin("Contact", "Address", Boolean.valueOf(isOuterJoin), "contactId", "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);
}
}
public static void setNameFields( GenericValue contactGV )
{
String firstName = UtilFormatOut.checkNull(contactGV.getString("firstName"));
String lastName = UtilFormatOut.checkNull(contactGV.getString("lastName"));
String prefix = UtilFormatOut.checkNull(contactGV.getString("prefix"));
String suffix = UtilFormatOut.checkNull(contactGV.getString("suffix"));
String profSuffix = UtilFormatOut.checkNull(contactGV.getString("profSuffix"));
String fullName = UtilFormatOut.checkNull(contactGV.getString("fullName"));;
if ( (lastName.length() == 0) && ( fullName.length() > 0) )
{
lastName = fullName;
contactGV.set("lastName", lastName);
} else
{
String flds[] = { prefix, firstName, lastName, suffix, profSuffix };
fullName = "";
for ( int i=0; i < flds.length; i++)
{
if ( flds[i].length() > 0 )
{
if ( fullName.length() > 0)
fullName = fullName + " " + flds[i];
else
fullName = flds[i];
}
}
contactGV.set("fullName", fullName);
}
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
*
* @return
*/
public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo,
GenericDelegator delegator) {
return new SecurityLinkInfo("Account", "accountId", false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -