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 java.sql.Timestamp;
020: import java.util.Calendar;
021: import java.util.List;
022:
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericValue;
027:
028: import com.sourcetap.sfa.event.DataMatrix;
029: import com.sourcetap.sfa.event.GenericEventProcessor;
030: import com.sourcetap.sfa.replication.GenericReplicator;
031: import com.sourcetap.sfa.util.UserInfo;
032:
033: /**
034: * DOCUMENT ME!
035: *
036: */
037: public class LeadRuleCriteriaEventProcessor extends
038: GenericEventProcessor {
039: public static final String module = LeadRuleCriteriaEventProcessor.class
040: .getName();
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @param userInfo
046: * @param delegator
047: * @param dataMatrix
048: *
049: * @return
050: */
051: protected int preUpdate(UserInfo userInfo,
052: GenericDelegator delegator, DataMatrix dataMatrix) {
053:
054: // Just process the first row for now.
055: GenericValue leadRuleCriteriaGV = null;
056:
057: try {
058: leadRuleCriteriaGV = dataMatrix.getCurrentBuffer()
059: .getGenericValue(0, "LeadAssignmentCriteria", true);
060: } catch (GenericEntityException e) {
061: Debug.logError(
062: "[LeadRuleCriteriaEventProcessor.preUpdate] Error getting generic value: "
063: + e.toString(), module);
064:
065: return STATUS_ERROR;
066: }
067:
068: // Set the time stamps.
069: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
070: .getTime());
071: leadRuleCriteriaGV.set("modifiedDate", now);
072:
073: // Store the current user ID in the "modified by" field.
074: leadRuleCriteriaGV.set("modifiedBy", userInfo.getPartyId());
075:
076: return STATUS_CONTINUE;
077: }
078:
079: /**
080: * DOCUMENT ME!
081: *
082: * @param userInfo
083: * @param delegator
084: * @param dataMatrix
085: *
086: * @return
087: */
088: protected int preInsert(UserInfo userInfo,
089: GenericDelegator delegator, DataMatrix dataMatrix) {
090:
091: // Just process the first row for now.
092: GenericValue leadRuleCriteriaGV = null;
093:
094: try {
095: leadRuleCriteriaGV = dataMatrix.getCurrentBuffer()
096: .getGenericValue(0, "LeadAssignmentCriteria", true);
097: } catch (GenericEntityException e) {
098: Debug.logError(
099: "[LeadQueueEventProcessor.preInsert] Error getting generic value: "
100: + e.getLocalizedMessage(), module);
101:
102: return STATUS_ERROR;
103: }
104:
105: // Generate new key for the leadQueue.
106: String criteriaId = GenericReplicator.getNextSeqId(
107: "LeadAssignmentCriteria", delegator);
108: leadRuleCriteriaGV.set("leadAssignmentCriteriaId", criteriaId);
109:
110: // Set the time stamps.
111: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
112: .getTime());
113: leadRuleCriteriaGV.set("createdDate", now);
114: leadRuleCriteriaGV.set("modifiedDate", now);
115:
116: // Store the current user ID in the "modified by" field.
117: leadRuleCriteriaGV.set("createdBy", userInfo.getPartyId());
118: leadRuleCriteriaGV.set("modifiedBy", userInfo.getPartyId());
119:
120: return STATUS_CONTINUE;
121: }
122:
123: /**
124: * DOCUMENT ME!
125: *
126: * @param userInfo
127: * @param entityNameList
128: * @param delegator
129: * @param dataMatrix
130: *
131: * @return
132: */
133: protected int postCreate(UserInfo userInfo, List entityNameList,
134: GenericDelegator delegator, DataMatrix dataMatrix) {
135:
136: // Get the empty generic values.
137: GenericValue leadRuleCriteriaGV = null;
138:
139: try {
140: leadRuleCriteriaGV = dataMatrix.getCurrentBuffer()
141: .getGenericValue(0, "LeadAssignmentCriteria", true);
142: } catch (GenericEntityException e) {
143: Debug.logError(
144: "[ContactEventProcessor.postCreate] Error getting generic value: "
145: + e.toString(), module);
146:
147: return STATUS_ERROR;
148: }
149:
150: // Set default values on the new record so they will be displayed for the user to see before saving.
151: // Active Flag
152: // if (DEBUG) Debug.logVerbose("Setting active flag to true");
153: // leadRuleCriteriaGV.set("activeFlag", new Boolean(true));
154: // Refresh the cache in the delegator so that dropdowns will show the new leadRule
155: delegator.getAndCache().clear();
156:
157: return STATUS_CONTINUE;
158: }
159:
160: /**
161: * DOCUMENT ME!
162: *
163: * @param userInfo
164: * @param delegator
165: * @param originatingEntityName
166: * @param entityGV
167: *
168: * @return
169: */
170: public int deleteAllRelated(UserInfo userInfo,
171: GenericDelegator delegator, String originatingEntityName,
172: GenericValue entityGV) {
173:
174: int status = STATUS_CONTINUE;
175:
176: return STATUS_CONTINUE;
177: }
178:
179: // public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo, GenericDelegator delegator)
180: // {
181: // return new SecurityLinkInfo( "Account", "accountId", false );
182: // }
183: }
|