01: /*
02: *
03: * Copyright (c) 2004 SourceTap - www.sourcetap.com
04: *
05: * The contents of this file are subject to the SourceTap Public License
06: * ("License"); You may not use this file except in compliance with the
07: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
10: * the specific language governing rights and limitations under the License.
11: *
12: * The above copyright notice and this permission notice shall be included
13: * in all copies or substantial portions of the Software.
14: *
15: */
16:
17: package com.sourcetap.sfa.note;
18:
19: import java.sql.Timestamp;
20: import java.util.Calendar;
21:
22: import org.ofbiz.entity.GenericDelegator;
23: import org.ofbiz.entity.GenericValue;
24:
25: import com.sourcetap.sfa.event.DataMatrix;
26: import com.sourcetap.sfa.event.GenericEventProcessor;
27: import com.sourcetap.sfa.replication.GenericReplicator;
28: import com.sourcetap.sfa.util.UserInfo;
29:
30: /**
31: * DOCUMENT ME!
32: *
33: */
34: public class AbstractNoteEP extends GenericEventProcessor {
35: public static final String module = AbstractNoteEP.class.getName();
36:
37: /**
38: * DOCUMENT ME!
39: *
40: * @param userInfo
41: * @param delegator
42: * @param dataMatrix
43: *
44: * @return
45: */
46: protected int preUpdate(UserInfo userInfo,
47: GenericDelegator delegator, DataMatrix dataMatrix) {
48:
49: GenericValue noteGV = dataMatrix.getCurrentBuffer()
50: .getGenericValue(0, 0);
51:
52: // Set the time stamps.
53: noteGV.set("modifiedDate", new Timestamp(Calendar.getInstance()
54: .getTime().getTime()));
55:
56: // Store the current user's party ID in the "modified by" field.
57: noteGV.set("modifiedBy", userInfo.getPartyId());
58:
59: return STATUS_CONTINUE;
60: }
61:
62: /**
63: * DOCUMENT ME!
64: *
65: * @param userInfo
66: * @param delegator
67: * @param dataMatrix
68: *
69: * @return
70: */
71: protected int preInsert(UserInfo userInfo,
72: GenericDelegator delegator, DataMatrix dataMatrix) {
73:
74: String userPartyId = userInfo.getPartyId();
75:
76: GenericValue noteGV = dataMatrix.getCurrentBuffer()
77: .getGenericValue(0, 0);
78: String noteId = noteGV.getString("noteId");
79:
80: if ((noteId == null) || (noteId.equals(""))) {
81: noteId = GenericReplicator.getNextSeqId("NoteAttachment",
82: delegator);
83: noteGV.set("noteId", noteId);
84: }
85:
86: // Set the time stamps.
87: Timestamp currentTime = new Timestamp(Calendar.getInstance()
88: .getTime().getTime());
89: noteGV.set("modifiedDate", currentTime);
90: noteGV.set("createdDate", currentTime);
91:
92: // Store the current user's Party ID in the "modified by" and "created by" fields.
93: noteGV.set("modifiedBy", userPartyId);
94: noteGV.set("createdBy", userPartyId);
95:
96: return STATUS_CONTINUE;
97: }
98:
99: }
|