📄 usereventprocessor.java
字号:
/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.user;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.util.UserInfo;
/**
* DOCUMENT ME!
*
*/
public class UserEventProcessor extends GenericEventProcessor {
public static final String module = UserEventProcessor.class.getName();
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
* @param dataMatrix
*
* @return
*/
protected int preUpdate(UserInfo userInfo, GenericDelegator delegator,
DataMatrix dataMatrix) {
Debug.logVerbose("-->[UserEventProcessor.preUpdate()]", module);
// Process just the first row for now.
GenericValue contactGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
0);
GenericValue partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
1);
GenericValue userLoginGV = dataMatrix.getCurrentBuffer()
.getGenericValue(0, 2);
GenericValue accountGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
3);
GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
4);
// Copy the contact ID to the address owner ID in case it is not already filled in.
String contactId = contactGV.getString("contactId");
addressGV.set("addressOwnerId", contactId);
// Copy the contact ID to the user Login Party ID in case it is not already filled in.
userLoginGV.set("partyId", contactId);
Debug.logVerbose("userLogin=" + userLoginGV.toString(), module);
// Set the time stamps.
contactGV.set("modifiedBy", userInfo.getPartyId());
addressGV.set("modifiedBy", userInfo.getPartyId());
contactGV.set("modifiedDate",
new Timestamp(Calendar.getInstance().getTime().getTime()));
addressGV.set("modifiedDate",
new Timestamp(Calendar.getInstance().getTime().getTime()));
return STATUS_CONTINUE;
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
* @param dataMatrix
*
* @return
*/
protected int preInsert(UserInfo userInfo, GenericDelegator delegator,
DataMatrix dataMatrix) {
Debug.logVerbose("in preInsert", module);
// Process just the first row for now.
GenericValue contactGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
0);
GenericValue partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
1);
GenericValue userLoginGV = dataMatrix.getCurrentBuffer()
.getGenericValue(0, 2);
GenericValue accountGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
3);
GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
4);
GenericValue roleGV = new GenericValue(delegator.getModelEntity("Role"));
roleGV.setDelegator( delegator );
GenericValue partyRoleGV = new GenericValue(delegator.getModelEntity(
"Party"));
partyRoleGV.setDelegator( delegator );
GenericValue contactAddressGV = new GenericValue(delegator.getModelEntity(
"Address"));
contactAddressGV.setDelegator ( delegator );
GenericValue contactPartyRoleGV = new GenericValue(delegator.getModelEntity(
"PartyRole"));
contactPartyRoleGV.setDelegator ( delegator );
String roleId = GenericReplicator.getNextSeqId("Party", delegator);
String contactId = GenericReplicator.getNextSeqId("Party", delegator);
String accountId = GenericReplicator.getNextSeqId("Account", delegator);
String addressId = GenericReplicator.getNextSeqId("Address", delegator);
String contactAddressId = GenericReplicator.getNextSeqId("Address",
delegator);
partyRoleGV.set("partyId", roleId);
roleGV.set("roleId", roleId);
roleGV.set("roleName",
accountGV.getString("accountName") + " Administrator");
roleGV.set("rolePath", roleId);
roleGV.set("accountId", accountId);
contactAddressGV.set("addressId", contactAddressId);
contactAddressGV.set("addressOwnerId", contactId);
contactAddressGV.set("addressOwnerType", "Contact");
contactAddressGV.set("isPrimary", "Y");
contactPartyRoleGV.set("partyId", contactId);
contactPartyRoleGV.set("roleTypeId", "SFA_ADMIN");
contactGV.set("roleId", roleId);
userInfo.setRoleId(roleId);
userInfo.setPartyId(contactId);
userInfo.setUserName(userLoginGV.getString("userLoginId"));
userInfo.setAccountId(accountId);
contactGV.set("contactId", contactId);
contactGV.set("contactOwnerId", contactId);
contactGV.set("accountId", accountId);
partyGV.set("partyId", contactId);
userLoginGV.set("partyId", contactId);
addressGV.set("addressId", addressId);
addressGV.set("addressOwnerId", accountId);
addressGV.set("addressOwnerType", "Account");
accountGV.set("accountOwnerId", contactId);
SecurityWrapper.addRoleInformation(dataMatrix, 0, userInfo, "",
"Account", accountId, delegator);
//set the account as base
accountGV.set("accountId", accountId);
accountGV.set("accountTypeId", "base");
// Make this address the primary one for the contact.
addressGV.set("isPrimary", "Y");
Debug.logVerbose("userLogin=" + userLoginGV.toString(), module);
Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
String userLoginId = userLoginGV.getString("userLoginId");
// Set the time stamps.
contactGV.set("createdDate", now);
contactGV.set("createdBy", contactId);
contactGV.set("modifiedBy", contactId);
contactGV.set("modifiedDate", now);
addressGV.set("createdDate", now);
addressGV.set("modifiedDate", now);
addressGV.set("createdBy", contactId);
addressGV.set("modifiedBy", contactId);
contactAddressGV.set("createdDate", now);
contactAddressGV.set("modifiedDate", now);
contactAddressGV.set("createdBy", contactId);
contactAddressGV.set("modifiedBy", contactId);
accountGV.set("createdDate", now);
accountGV.set("modifiedDate", now);
accountGV.set("createdBy", contactId);
accountGV.set("modifiedBy", contactId);
// default hiredate on contact.
contactGV.set("hireDate", now);
// Set the contact type to 'user'
contactGV.set("contactTypeId", "user");
dataMatrix.addEntity("Party", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(partyRoleGV);
dataMatrix.addEntity("Role", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(roleGV);
dataMatrix.addEntity("Address", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(contactAddressGV);
dataMatrix.addEntity("PartyRole", false, true);
dataMatrix.getCurrentBuffer().getContentsRow(0).add(contactPartyRoleGV);
return STATUS_CONTINUE;
}
/**
* copy standard template data to this account.
* Create a customizable sales process by copying the default sales process
*
* @param userInfo
* @param delegator
* @param dataMatrix
*
* @return
*/
protected int postInsert(UserInfo userInfo, GenericDelegator delegator, DataMatrix dataMatrix)
{
try {
GenericValue contactGV = dataMatrix.getCurrentBuffer().getGenericValue(0,0);
String contactId = contactGV.getString("contactId");
Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
// copy the standard process to this company, so that it can be modified
GenericValue dealStageType = delegator.findByPrimaryKey(new GenericPK( delegator.getModelEntity("DealStageType"), UtilMisc.toMap("dealStageTypeId","1")));
String origStageTypeId = dealStageType.getString("dealStageTypeId");
String newStageTypeId = GenericReplicator.getNextSeqId("DealStageType", delegator);
dealStageType.set("dealStageTypeId", newStageTypeId);
dealStageType.set("accountId", userInfo.getAccountId());
// Set the time stamps.
dealStageType.set("createdDate", now);
dealStageType.set("createdBy", contactId);
dealStageType.set("modifiedBy", contactId);
dealStageType.set("modifiedDate", now);
ArrayList data = new ArrayList();
data.add(dealStageType);
List stages = delegator.findByAnd(delegator.getModelEntity("DealStage"), UtilMisc.toMap("stageTypeId", origStageTypeId), null);
Iterator stageIter = stages.iterator();
while ( stageIter.hasNext() )
{
GenericValue stageGV = (GenericValue) stageIter.next();
String origStageId = stageGV.getString("stageId");
String newStageId = GenericReplicator.getNextSeqId("DealStage",delegator);
stageGV.set("stageId", newStageId);
stageGV.set("stageTypeId", newStageTypeId);
// Set the time stamps.
stageGV.set("createdDate", now);
stageGV.set("createdBy", contactId);
stageGV.set("modifiedBy", contactId);
stageGV.set("modifiedDate", now);
data.add(stageGV);
List steps = delegator.findByAnd(delegator.getModelEntity("DealStageSteps"), UtilMisc.toMap("dealStageId", origStageId), null);
Iterator stepIter= steps.iterator();
while ( stepIter.hasNext() )
{
GenericValue stepGV = (GenericValue) stepIter.next();
String newStepId = GenericReplicator.getNextSeqId("DealStageSteps", delegator);
stepGV.set("dealStageStepId", newStepId);
stepGV.set("dealStageId", newStageId);
stepGV.set("dealStageTypeId", newStageTypeId);
// Set the time stamps.
stepGV.set("createdDate", now);
stepGV.set("createdBy", contactId);
stepGV.set("modifiedBy", contactId);
stepGV.set("modifiedDate", now);
data.add(stepGV);
}
}
delegator.storeAll(data);
}
catch (Exception e)
{
Debug.logError("Unable to copy Sales Process for new company", module);
}
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) {
Debug.logVerbose("[postCreate]", module);
// Get the empty generic values.
// Process just the first row for now.
GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,4);
// Country
Debug.logVerbose("Setting country to \"USA\"", module);
addressGV.set("country", "USA");
return STATUS_CONTINUE;
}
/**
* DOCUMENT ME!
*
* @param userInfo
* @param delegator
*
* @return
*/
public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo,
GenericDelegator delegator) {
return new SecurityLinkInfo("Account", "accountId", true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -