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.issue;
018:
019: import java.sql.Timestamp;
020:
021: import org.ofbiz.entity.GenericDelegator;
022: import org.ofbiz.entity.GenericValue;
023:
024: import com.sourcetap.sfa.event.DataMatrix;
025: import com.sourcetap.sfa.event.GenericEventProcessor;
026: import com.sourcetap.sfa.replication.GenericReplicator;
027: import com.sourcetap.sfa.util.UserInfo;
028:
029: /**
030: * DOCUMENT ME!
031: *
032: */
033: public class IssueEventProcessor extends GenericEventProcessor {
034: public static final String module = IssueEventProcessor.class
035: .getName();
036:
037: /**
038: * DOCUMENT ME!
039: *
040: * @param userInfo
041: * @param delegator
042: * @param dataMatrix
043: *
044: * @return
045: */
046: protected int preUpdate(UserInfo userInfo,
047: GenericDelegator delegator, DataMatrix dataMatrix) {
048:
049: // Just process the first row for now.
050: GenericValue itIssueGV = dataMatrix.getCurrentBuffer()
051: .getGenericValue(0, 0);
052:
053: Timestamp now = new Timestamp(new java.util.Date().getTime());
054:
055: // Store the current user ID in the "modified by" field.
056: String userPartyId = userInfo.getPartyId();
057: String issueId = itIssueGV.getString("issueId");
058:
059: itIssueGV.set("issueId", issueId);
060: itIssueGV.set("modifiedBy", userPartyId);
061: itIssueGV.set("modifiedDate", now);
062:
063: //Store the issue information in the history table
064: GenericValue itIssueHistoryGV = new GenericValue(delegator
065: .getModelEntity("ItIssueHistory"));
066: itIssueHistoryGV.setDelegator(delegator);
067: String historyId = GenericReplicator.getNextSeqId(
068: "ItIssueHistory", delegator);
069:
070: GenericValue largeDataGV = new GenericValue(delegator
071: .getModelEntity("LargeData"));
072: largeDataGV.setDelegator(delegator);
073: String dataId = GenericReplicator.getNextSeqId("LargeData",
074: delegator);
075:
076: itIssueHistoryGV.set("historyId", historyId);
077: itIssueHistoryGV.set("dataId", dataId);
078: itIssueHistoryGV.set("issueId", itIssueGV.getString("issueId"));
079: itIssueHistoryGV.set("statusId", itIssueGV
080: .getString("statusId"));
081: itIssueHistoryGV.set("assignedTo", itIssueGV
082: .getString("assignedTo"));
083: itIssueHistoryGV.set("priorityId", itIssueGV
084: .getString("priorityId"));
085: itIssueHistoryGV.set("shortName", itIssueGV
086: .getString("shortName"));
087: itIssueHistoryGV.set("createdBy", userPartyId);
088: itIssueHistoryGV.set("createdDate", now);
089: itIssueHistoryGV.set("modifiedBy", userPartyId);
090: itIssueHistoryGV.set("modifiedDate", now);
091:
092: String notes = itIssueGV.getString("notes");
093: largeDataGV.set("dataId", dataId);
094: largeDataGV.set("dataValue", notes);
095:
096: //clear the issues notes field (it will be stored in the Large Data table )
097: itIssueGV.set("notes", "");
098:
099: // Add the IT Issue History to the data matrix so it will be saved.
100: dataMatrix.addEntity("ItIssueHistory", false, true);
101: dataMatrix.getCurrentBuffer().getContentsRow(0).add(
102: itIssueHistoryGV);
103:
104: // Add the Large Data (note) to the data matrix so it will be saved.
105: dataMatrix.addEntity("LargeData", false, true);
106: dataMatrix.getCurrentBuffer().getContentsRow(0)
107: .add(largeDataGV);
108:
109: return STATUS_CONTINUE;
110: }
111:
112: /**
113: * DOCUMENT ME!
114: *
115: * @param userInfo
116: * @param delegator
117: * @param dataMatrix
118: *
119: * @return
120: */
121: protected int preInsert(UserInfo userInfo,
122: GenericDelegator delegator, DataMatrix dataMatrix) {
123:
124: // Just process the issue...
125: GenericValue itIssueGV = dataMatrix.getCurrentBuffer()
126: .getGenericValue(0, 0);
127:
128: Timestamp now = new Timestamp(new java.util.Date().getTime());
129:
130: // Store the current user ID in the "modified by" field.
131: String userPartyId = userInfo.getPartyId();
132:
133: String issueId = GenericReplicator.getNextSeqId("ItIssue",
134: delegator);
135:
136: itIssueGV.set("issueId", issueId);
137: itIssueGV.set("modifiedBy", userPartyId);
138: itIssueGV.set("modifiedDate", now);
139: itIssueGV.set("createdBy", userPartyId);
140: itIssueGV.set("createdDate", now);
141:
142: //Store the issue information in the history table
143: GenericValue itIssueHistoryGV = new GenericValue(delegator
144: .getModelEntity("ItIssueHistory"));
145: itIssueHistoryGV.setDelegator(delegator);
146: String historyId = GenericReplicator.getNextSeqId(
147: "ItIssueHistory", delegator);
148:
149: GenericValue largeDataGV = new GenericValue(delegator
150: .getModelEntity("LargeData"));
151: largeDataGV.setDelegator(delegator);
152: String dataId = GenericReplicator.getNextSeqId("LargeData",
153: delegator);
154:
155: itIssueHistoryGV.set("historyId", historyId);
156: itIssueHistoryGV.set("dataId", dataId);
157: itIssueHistoryGV.set("issueId", itIssueGV.getString("issueId"));
158: itIssueHistoryGV.set("statusId", itIssueGV
159: .getString("statusId"));
160: itIssueHistoryGV.set("assignedTo", itIssueGV
161: .getString("assignedTo"));
162: itIssueHistoryGV.set("priorityId", itIssueGV
163: .getString("priorityId"));
164: itIssueHistoryGV.set("shortName", itIssueGV
165: .getString("shortName"));
166: itIssueHistoryGV.set("modifiedBy", userPartyId);
167: itIssueHistoryGV.set("modifiedDate", now);
168:
169: String notes = itIssueGV.getString("notes");
170: largeDataGV.set("dataId", dataId);
171: largeDataGV.set("dataValue", notes);
172:
173: //clear the issues notes field (it will be stored in the Large Data table )
174: itIssueGV.set("notes", "");
175:
176: //show what we have
177:
178: // Add the IT Issue History to the data matrix so it will be saved.
179: dataMatrix.addEntity("ItIssueHistory", false, true);
180: dataMatrix.getCurrentBuffer().getContentsRow(0).add(
181: itIssueHistoryGV);
182:
183: // Add the Large Data (note) to the data matrix so it will be saved.
184: dataMatrix.addEntity("LargeData", false, true);
185: dataMatrix.getCurrentBuffer().getContentsRow(0)
186: .add(largeDataGV);
187:
188: return STATUS_CONTINUE;
189: }
190: }
|