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.note;
018:
019: import java.sql.Timestamp;
020: import java.util.Calendar;
021: import java.util.List;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.ofbiz.entity.GenericDelegator;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.entity.condition.EntityOperator;
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.replication.GenericReplicator;
034: import com.sourcetap.sfa.ui.UICache;
035: import com.sourcetap.sfa.ui.UIWebScreenSection;
036: import com.sourcetap.sfa.util.QueryInfo;
037: import com.sourcetap.sfa.util.UserInfo;
038:
039: /**
040: * DOCUMENT ME!
041: *
042: */
043: public class AbstractNoteWEP extends GenericWebEventProcessor {
044: public static final String module = AbstractNoteWEP.class.getName();
045:
046: // overide the default. Link Contact and Deal via the OpportunityContact entity
047: protected void addUseQueryParameterClauses(
048: UIWebScreenSection uiWebScreenSection, QueryInfo queryInfo,
049: List relatedSearchClauses, String primaryEntityName,
050: HttpServletRequest request) {
051: String[] linkParams = { "accountId", "contactId", "dealId",
052: "activityId", "productId", "leadId" };
053: String[] linkEntities = { "Account", "Contact", "Deal",
054: "Activity", "Product", "Lead" };
055:
056: for (int i = 0; i < linkParams.length; i++) {
057: String linkValue = request.getParameter(linkParams[i]);
058:
059: if ((linkValue != null) && (linkValue.length() > 0)) {
060:
061: queryInfo.addJoin("NoteAttachment", "NoteLink",
062: Boolean.FALSE, "noteId", "noteId");
063: queryInfo.addCondition("NoteLink", "noteLinkType",
064: EntityOperator.EQUALS, linkEntities[i]);
065: queryInfo.addCondition("NoteLink", "noteLinkId",
066: EntityOperator.EQUALS, linkValue);
067: }
068: }
069: }
070:
071: protected int preInsert(UserInfo userInfo,
072: UIWebScreenSection uiWebScreenSection,
073: HttpServletRequest request, HttpServletResponse response,
074: GenericDelegator delegator,
075: GenericEventProcessor eventProcessor,
076: DataMatrix dataMatrix, UICache uiCache) {
077:
078: GenericValue noteGV = dataMatrix.getCurrentBuffer()
079: .getGenericValue(0, 0);
080: String noteId = noteGV.getString("noteId");
081:
082: if ((noteId == null) || (noteId.equals(""))) {
083: noteId = GenericReplicator.getNextSeqId("NoteAttachment",
084: delegator);
085: }
086:
087: noteGV.set("noteId", noteId);
088:
089: String linkId = "";
090: String userPartyId = userInfo.getPartyId();
091: // Set the time stamps.
092: Timestamp currentTime = new Timestamp(Calendar.getInstance()
093: .getTime().getTime());
094:
095: String[] linkParams = { "accountId", "contactId", "dealId",
096: "activityId", "productId", "leadId" };
097: String[] linkEntities = { "Account", "Contact", "Deal",
098: "Activity", "Product", "Lead" };
099:
100: for (int i = 0; i < linkParams.length; i++) {
101: String linkValue = request.getParameter(linkParams[i]);
102:
103: if ((linkValue != null) && (linkValue.length() > 0)) {
104:
105: // Add the owner to the participants list.
106: GenericValue noteLinkGV = new GenericValue(delegator
107: .getModelEntity("NoteLink"));
108: noteLinkGV.setDelegator(delegator);
109:
110: noteLinkGV.set("noteId", noteId);
111: noteLinkGV.set("noteLinkType", linkEntities[i]);
112: noteLinkGV.set("noteLinkId", linkValue);
113: noteLinkGV.set("createdBy", userPartyId);
114: noteLinkGV.set("createdDate", currentTime);
115: noteLinkGV.set("modifiedBy", userPartyId);
116: noteLinkGV.set("modifiedDate", currentTime);
117:
118: // Add the Activity Contact to the data matrix so it will be saved.
119: dataMatrix.addEntity("NoteLink", false, true);
120: dataMatrix.getCurrentBuffer().getContentsRow(0).add(
121: noteLinkGV);
122:
123: break;
124: }
125: }
126:
127: return STATUS_CONTINUE;
128: }
129:
130: }
|