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.opportunity;
018:
019: import java.sql.Timestamp;
020: import java.util.Calendar;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.ofbiz.base.util.Debug;
026: import org.ofbiz.entity.GenericDelegator;
027: import org.ofbiz.entity.GenericEntityException;
028: import org.ofbiz.entity.GenericValue;
029:
030: import com.sourcetap.sfa.event.DataMatrix;
031: import com.sourcetap.sfa.event.GenericEventProcessor;
032: import com.sourcetap.sfa.event.GenericWebEventProcessor;
033: import com.sourcetap.sfa.ui.UICache;
034: import com.sourcetap.sfa.ui.UIScreenSection;
035: import com.sourcetap.sfa.ui.UIWebScreenSection;
036: import com.sourcetap.sfa.util.UserInfo;
037:
038: /**
039: * DOCUMENT ME!
040: *
041: */
042: public class OpportunityWebEventProcessor extends
043: GenericWebEventProcessor {
044: public static final String module = OpportunityWebEventProcessor.class
045: .getName();
046:
047: /**
048: * DOCUMENT ME!
049: *
050: * @param userInfo
051: * @param uiWebScreenSection
052: * @param request
053: * @param response
054: * @param delegator
055: * @param eventProcessor
056: * @param dataMatrix
057: * @param uiCache
058: *
059: * @return
060: */
061: protected int preInsert(UserInfo userInfo,
062: UIWebScreenSection uiWebScreenSection,
063: HttpServletRequest request, HttpServletResponse response,
064: GenericDelegator delegator,
065: GenericEventProcessor eventProcessor,
066: DataMatrix dataMatrix, UICache uiCache) {
067:
068: // If the screen section is on the composite account create window, need to copy the account ID
069: // from the account to the Opportunity.
070:
071: if (request.getAttribute("com.sourcetap.sfa.account.accountId") != null) {
072:
073: String accountId = (String) request
074: .getAttribute("com.sourcetap.sfa.account.accountId");
075: GenericValue opportunityGV = dataMatrix.getCurrentBuffer()
076: .getGenericValue(0, 0);
077:
078: opportunityGV.set("accountId", accountId);
079: }
080:
081: return STATUS_CONTINUE;
082: }
083:
084: /**
085: * DOCUMENT ME!
086: *
087: * @param userInfo
088: * @param uiWebScreenSection
089: * @param request
090: * @param response
091: * @param delegator
092: * @param eventProcessor
093: * @param dataMatrix
094: * @param uiCache
095: *
096: * @return
097: */
098: protected int postInsert(UserInfo userInfo,
099: UIWebScreenSection uiWebScreenSection,
100: HttpServletRequest request, HttpServletResponse response,
101: GenericDelegator delegator,
102: GenericEventProcessor eventProcessor,
103: DataMatrix dataMatrix, UICache uiCache) {
104: // If the screen section is on the composite account or contact create window, and a contact was created,
105: // need to create an opportunity-contact record for the created opportunity and contact.
106:
107: if (request.getAttribute("com.sourcetap.sfa.contact.contactId") != null) {
108:
109: String contactId = (String) request
110: .getAttribute("com.sourcetap.sfa.contact.contactId");
111: GenericValue dealGV = dataMatrix.getCurrentBuffer()
112: .getGenericValue(0, 0);
113: String dealId = dealGV.getString("dealId");
114:
115: // Create the new OpportunityContact generic value.
116: GenericValue opportunityContactGV = new GenericValue(
117: delegator.getModelEntity("OpportunityContact"));
118: opportunityContactGV.setDelegator(delegator);
119: Timestamp currentTime = new Timestamp(Calendar
120: .getInstance().getTime().getTime());
121: opportunityContactGV.set("dealId", dealId);
122: opportunityContactGV.set("contactId", contactId);
123: opportunityContactGV
124: .set("createdBy", userInfo.getPartyId());
125: opportunityContactGV.set("createdDate", currentTime);
126: opportunityContactGV.set("modifiedBy", userInfo
127: .getPartyId());
128: opportunityContactGV.set("modifiedDate", currentTime);
129:
130: // Save the OpportunityContact.
131: try {
132:
133: delegator.create(opportunityContactGV);
134: } catch (GenericEntityException e) {
135: Debug
136: .logError(
137: "[OpportunityWebEventProcessor.postInsert] Error inserting new OpportunityContact. Save continued without inserting OpportunityContact.",
138: module);
139: }
140: }
141:
142: return STATUS_CONTINUE;
143: }
144:
145: /**
146: * DOCUMENT ME!
147: *
148: * @param userInfo
149: * @param screenName
150: * @param sectionName
151: * @param delegator
152: * @param uiCache
153: *
154: * @return
155: *
156: * @throws GenericEntityException
157: */
158: protected UIWebScreenSection getUiWebScreenSection(
159: UserInfo userInfo, String screenName, String sectionName,
160: GenericDelegator delegator, UICache uiCache)
161: throws GenericEntityException {
162: // This method is here so a child class can specify a different screen section class.
163:
164: UIScreenSection uiScreenSection = uiCache.getUiScreenSection(
165: screenName, sectionName, userInfo.getPartyId());
166:
167: if (uiScreenSection == null) {
168:
169: UIWebScreenSectionOpportunity uiWebScreenSectionOpportunity = new UIWebScreenSectionOpportunity(
170: userInfo, screenName, sectionName, delegator,
171: uiCache);
172: uiCache.putUiScreenSection(screenName, sectionName,
173: userInfo.getPartyId(),
174: (UIScreenSection) uiWebScreenSectionOpportunity);
175: return (UIWebScreenSection) uiWebScreenSectionOpportunity;
176: } else {
177: return (UIWebScreenSection) uiScreenSection;
178: }
179:
180: }
181:
182: /**
183: * This function gets the application path to be used to reconstruct the URI when a
184: * UI History record is logged. Example: "/accounts"
185: * @author John Nutting
186: * @param url The URL used to open the screen section
187: * @return String containing the application path
188: */
189: protected String getUiHistoryAppPath(String url) {
190: return "/deals";
191: }
192:
193: /**
194: * This function gets the description to store in the UI history table. This description
195: * will show up in the UI History drop list.
196: * @author John Nutting
197: * @param dataMatrix DataMatrix object containing the data from the screen
198: * @param delegator Generic delegator through which the data base is accessed
199: * @param action The action being performed on the screen
200: * @param uiWebScreenSection The UIWebScreenSection being used to construct the screen section
201: * @return String containing the UI History description
202: */
203: protected String getUiHistoryDescription(DataMatrix dataMatrix,
204: GenericDelegator delegator, String action,
205: UIWebScreenSection uiWebScreenSection) {
206: GenericValue primaryGV = dataMatrix.getCurrentBuffer()
207: .getGenericValue(0, 0);
208:
209: return "Opportunity: " + primaryGV.getString("dealName");
210: }
211: }
|