001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.lead;
018:
019: import com.sourcetap.sfa.attachment.AbstractAttachmentEP;
020: import com.sourcetap.sfa.event.*;
021: import com.sourcetap.sfa.replication.*;
022: import com.sourcetap.sfa.security.*;
023: import com.sourcetap.sfa.util.UserInfo;
024:
025: import org.ofbiz.entity.*;
026: import org.ofbiz.entity.model.*;
027: import org.ofbiz.base.util.*;
028:
029: import java.sql.Timestamp;
030:
031: import java.util.*;
032:
033: /**
034: * DOCUMENT ME!
035: *
036: */
037: public class LeadRuleEventProcessor extends GenericEventProcessor {
038: public static final String module = LeadRuleEventProcessor.class
039: .getName();
040:
041: /**
042: * DOCUMENT ME!
043: *
044: * @param userInfo
045: * @param delegator
046: * @param dataMatrix
047: *
048: * @return
049: */
050: protected int preUpdate(UserInfo userInfo,
051: GenericDelegator delegator, DataMatrix dataMatrix) {
052:
053: // Just process the first row for now.
054: GenericValue leadRuleGV = null;
055:
056: try {
057: leadRuleGV = dataMatrix.getCurrentBuffer().getGenericValue(
058: 0, "LeadAssignmentRule", true);
059: } catch (GenericEntityException e) {
060: Debug.logError(
061: "[LeadQueueEventProcessor.preUpdate] Error getting generic value: "
062: + e.toString(), module);
063:
064: return STATUS_ERROR;
065: }
066:
067: // Set the time stamps.
068: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
069: .getTime());
070: leadRuleGV.set("modifiedDate", now);
071:
072: // Store the current user ID in the "modified by" field.
073: leadRuleGV.set("modifiedBy", userInfo.getPartyId());
074:
075: return STATUS_CONTINUE;
076: }
077:
078: /**
079: * DOCUMENT ME!
080: *
081: * @param userInfo
082: * @param delegator
083: * @param dataMatrix
084: *
085: * @return
086: */
087: protected int preInsert(UserInfo userInfo,
088: GenericDelegator delegator, DataMatrix dataMatrix) {
089:
090: // Just process the first row for now.
091: GenericValue leadRuleGV = null;
092:
093: try {
094: leadRuleGV = dataMatrix.getCurrentBuffer().getGenericValue(
095: 0, "LeadAssignmentRule", true);
096: } catch (GenericEntityException e) {
097: Debug.logError(
098: "[LeadQueueEventProcessor.preInsert] Error getting generic value: "
099: + e.getLocalizedMessage(), module);
100:
101: return STATUS_ERROR;
102: }
103:
104: // Generate new key for the leadQueue.
105: String ruleId = GenericReplicator.getNextSeqId(
106: "LeadAssignmentRule", delegator);
107: leadRuleGV.set("leadAssignmentRuleId", ruleId);
108:
109: // Set the time stamps.
110: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
111: .getTime());
112: leadRuleGV.set("createdDate", now);
113: leadRuleGV.set("modifiedDate", now);
114:
115: // Store the current user ID in the "modified by" field.
116: leadRuleGV.set("createdBy", userInfo.getPartyId());
117: leadRuleGV.set("modifiedBy", userInfo.getPartyId());
118:
119: leadRuleGV.set("accountId", userInfo.getAccountId());
120:
121: return STATUS_CONTINUE;
122: }
123:
124: /**
125: * DOCUMENT ME!
126: *
127: * @param userInfo
128: * @param entityNameList
129: * @param delegator
130: * @param dataMatrix
131: *
132: * @return
133: */
134: protected int postCreate(UserInfo userInfo, List entityNameList,
135: GenericDelegator delegator, DataMatrix dataMatrix) {
136:
137: // Get the empty generic values.
138: GenericValue leadRuleGV = null;
139:
140: try {
141: leadRuleGV = dataMatrix.getCurrentBuffer().getGenericValue(
142: 0, "LeadAssignmentRule", true);
143: } catch (GenericEntityException e) {
144: Debug.logError(
145: "[ContactEventProcessor.postCreate] Error getting generic value: "
146: + e.toString(), module);
147:
148: return STATUS_ERROR;
149: }
150:
151: // Set default values on the new record so they will be displayed for the user to see before saving.
152: // Active Flag
153: leadRuleGV.set("activeFlag", new Boolean(true));
154:
155: // Refresh the cache in the delegator so that dropdowns will show the new leadRule
156: delegator.getAndCache().clear();
157:
158: return STATUS_CONTINUE;
159: }
160:
161: /**
162: * DOCUMENT ME!
163: *
164: * @param userInfo
165: * @param delegator
166: * @param originatingEntityName
167: * @param entityGV
168: *
169: * @return
170: */
171: public int deleteAllRelated(UserInfo userInfo,
172: GenericDelegator delegator, String originatingEntityName,
173: GenericValue entityGV) {
174:
175: int status = STATUS_CONTINUE;
176:
177: return STATUS_CONTINUE;
178: }
179:
180: /* public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo, GenericDelegator delegator)
181: {
182: return new SecurityLinkInfo( "Account", "accountId", false );
183: }
184: */
185: }
|