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.code;
018:
019: import java.sql.Timestamp;
020: import java.util.Calendar;
021:
022: import org.ofbiz.entity.GenericDelegator;
023: import org.ofbiz.entity.GenericValue;
024:
025: import com.sourcetap.sfa.event.DataMatrix;
026: import com.sourcetap.sfa.event.GenericEventProcessor;
027: import com.sourcetap.sfa.util.UserInfo;
028:
029: /**
030: * DOCUMENT ME!
031: *
032: */
033: public class CodeEventProcessor extends GenericEventProcessor {
034:
035: /**
036: * DOCUMENT ME!
037: *
038: * @param userInfo
039: * @param delegator
040: * @param dataMatrix
041: *
042: * @return
043: */
044: protected int preUpdate(UserInfo userInfo,
045: GenericDelegator delegator, DataMatrix dataMatrix) {
046:
047: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
048: .getTime());
049:
050: // Process each row.
051: for (int row = 0; row < dataMatrix.getCurrentBuffer()
052: .getContents().size(); row++) {
053: GenericValue codeGV = dataMatrix.getCurrentBuffer()
054: .getGenericValue(row, 0);
055:
056: // Set the time stamps.
057: codeGV.set("modifiedDate", now);
058: codeGV.set("modifiedDate", now);
059:
060: // Store the current user's party ID in the "modified by" field.
061: codeGV.set("modifiedBy", userInfo.getPartyId());
062: codeGV.set("modifiedBy", userInfo.getPartyId());
063: }
064:
065: return STATUS_CONTINUE;
066: }
067:
068: /**
069: * DOCUMENT ME!
070: *
071: * @param userInfo
072: * @param delegator
073: * @param dataMatrix
074: *
075: * @return
076: */
077: protected int preInsert(UserInfo userInfo,
078: GenericDelegator delegator, DataMatrix dataMatrix) {
079:
080: Timestamp now = new Timestamp(Calendar.getInstance().getTime()
081: .getTime());
082:
083: // Process each row.
084: for (int row = 0; row < dataMatrix.getCurrentBuffer()
085: .getContents().size(); row++) {
086: GenericValue codeGV = dataMatrix.getCurrentBuffer()
087: .getGenericValue(row, 0);
088:
089: // Set the time stamps.
090: codeGV.set("modifiedDate", now);
091: codeGV.set("modifiedDate", now);
092:
093: // Store the current user's party ID in the "modified by" field.
094: codeGV.set("modifiedBy", userInfo.getPartyId());
095: codeGV.set("modifiedBy", userInfo.getPartyId());
096: }
097:
098: return STATUS_CONTINUE;
099: }
100:
101: /**
102: * DOCUMENT ME!
103: *
104: * @param userInfo
105: * @param delegator
106: * @param originatingEntityName
107: * @param entityGV
108: *
109: * @return
110: */
111: public int deleteAllRelated(UserInfo userInfo,
112: GenericDelegator delegator, String originatingEntityName,
113: GenericValue entityGV) {
114:
115: int status = STATUS_CONTINUE;
116:
117: // Delete any related Codes associated with this code. Set the allowRecursive flag to true.
118: status = deleteOneRelated(userInfo, delegator, entityGV,
119: "child", "Code", originatingEntityName,
120: new GenericEventProcessor(), true);
121:
122: return status;
123: }
124: }
|