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.customization;
018:
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericValue;
027: import org.ofbiz.entity.model.ModelEntity;
028:
029: import com.sourcetap.sfa.event.DataMatrix;
030: import com.sourcetap.sfa.event.GenericEventProcessor;
031: import com.sourcetap.sfa.util.UserInfo;
032:
033: /**
034: * DOCUMENT ME!
035: *
036: */
037: public class UIScreenSectionEventProcessor extends
038: GenericEventProcessor {
039: public static final String module = UIScreenSectionEventProcessor.class
040: .getName();
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @param userInfo
046: * @param delegator
047: * @param dataMatrix
048: *
049: * @return
050: */
051: protected int postInsert(UserInfo userInfo,
052: GenericDelegator delegator, DataMatrix dataMatrix) {
053:
054: // Get the current values.
055: GenericValue uiScreenSectionGV = dataMatrix.getCurrentBuffer()
056: .getGenericValue(0, 0);
057: String sectionId = uiScreenSectionGV.getString("sectionId");
058:
059: // Get the original values so we can see if this is a copy or a regular insert.
060: GenericValue uiScreenSectionGVOrig = dataMatrix
061: .getOriginalBuffer().getGenericValue(0, 0);
062: String sectionIdOrig = uiScreenSectionGVOrig
063: .getString("sectionId");
064:
065: if (sectionIdOrig.equals("") || (sectionIdOrig == null)) {
066: // The display object ID was not filled in yet when the screen was displayed last. This is
067: // a regular insert. Just let it proceed normally.
068: } else {
069: // This is a copy of an existing screen section.
070:
071: //////////
072: // Copy all the screen section entities from the original screen section.
073: //////////
074: HashMap uiScreenSectionEntityFindMap = new HashMap();
075: uiScreenSectionEntityFindMap
076: .put("sectionId", sectionIdOrig);
077:
078: try {
079: // Get the List of original screen section entities.
080: List uiScreenSectionEntityGVLOrig = delegator
081: .findByAnd("UiScreenSectionEntity",
082: uiScreenSectionEntityFindMap);
083: Iterator uiScreenSectionEntityGVIOrig = uiScreenSectionEntityGVLOrig
084: .iterator();
085: ModelEntity uiScreenSectionEntityME = delegator
086: .getModelEntity("UiScreenSectionEntity");
087:
088: while (uiScreenSectionEntityGVIOrig.hasNext()) {
089: GenericValue uiScreenSectionEntityGVOrig = (GenericValue) uiScreenSectionEntityGVIOrig
090: .next();
091: String entityIdOrig = (uiScreenSectionEntityGVOrig
092: .getString("entityId") == null) ? ""
093: : uiScreenSectionEntityGVOrig
094: .getString("entityId");
095:
096: // Get values from the original screen section entity.
097: String isUpdateableOrig = (uiScreenSectionEntityGVOrig
098: .getString("isUpdateable") == null) ? ""
099: : uiScreenSectionEntityGVOrig
100: .getString("isUpdateable");
101: String relationTitleOrig = (uiScreenSectionEntityGVOrig
102: .getString("relationTitle") == null) ? ""
103: : uiScreenSectionEntityGVOrig
104: .getString("relationTitle");
105: String relationByAndFieldsOrig = (uiScreenSectionEntityGVOrig
106: .getString("relationByAndFields") == null) ? ""
107: : uiScreenSectionEntityGVOrig
108: .getString("relationByAndFields");
109: String relationOrderByFieldsOrig = (uiScreenSectionEntityGVOrig
110: .getString("relationOrderByFields") == null) ? ""
111: : uiScreenSectionEntityGVOrig
112: .getString("relationOrderByFields");
113: String retrieveOrderOrig = (uiScreenSectionEntityGVOrig
114: .getString("retrieveOrder") == null) ? ""
115: : uiScreenSectionEntityGVOrig
116: .getString("retrieveOrder");
117: String insertOrderOrig = (uiScreenSectionEntityGVOrig
118: .getString("insertOrder") == null) ? ""
119: : uiScreenSectionEntityGVOrig
120: .getString("insertOrder");
121: String updateOrderOrig = (uiScreenSectionEntityGVOrig
122: .getString("updateOrder") == null) ? ""
123: : uiScreenSectionEntityGVOrig
124: .getString("updateOrder");
125: String deleteOrderOrig = (uiScreenSectionEntityGVOrig
126: .getString("deleteOrder") == null) ? ""
127: : uiScreenSectionEntityGVOrig
128: .getString("deleteOrder");
129: String isOuterJoinedOrig = (uiScreenSectionEntityGVOrig
130: .getString("isOuterJoined") == null) ? ""
131: : uiScreenSectionEntityGVOrig
132: .getString("isOuterJoined");
133: String hasSequenceKeyOrig = (uiScreenSectionEntityGVOrig
134: .getString("hasSequenceKey") == null) ? ""
135: : uiScreenSectionEntityGVOrig
136: .getString("hasSequenceKey");
137:
138: // Create the new screen section entity using the new section ID.
139: GenericValue uiScreenSectionEntityGV = new GenericValue(
140: uiScreenSectionEntityME);
141: uiScreenSectionEntityGV.setDelegator(delegator);
142: uiScreenSectionEntityGV.set("sectionId", sectionId);
143: uiScreenSectionEntityGV.set("entityId",
144: entityIdOrig);
145: uiScreenSectionEntityGV.set("isUpdateable",
146: isUpdateableOrig);
147: uiScreenSectionEntityGV.set("relationTitle",
148: relationTitleOrig);
149: uiScreenSectionEntityGV.set("relationByAndFields",
150: relationByAndFieldsOrig);
151: uiScreenSectionEntityGV.set(
152: "relationOrderByFields",
153: relationOrderByFieldsOrig);
154: uiScreenSectionEntityGV.set("retrieveOrder", Long
155: .valueOf(retrieveOrderOrig));
156: uiScreenSectionEntityGV.set("insertOrder", Long
157: .valueOf(insertOrderOrig));
158: uiScreenSectionEntityGV.set("updateOrder", Long
159: .valueOf(updateOrderOrig));
160: uiScreenSectionEntityGV.set("deleteOrder", Long
161: .valueOf(deleteOrderOrig));
162: uiScreenSectionEntityGV.set("isOuterJoined",
163: isOuterJoinedOrig);
164: uiScreenSectionEntityGV.set("hasSequenceKey",
165: hasSequenceKeyOrig);
166:
167: delegator.create(uiScreenSectionEntityGV);
168: }
169: } catch (GenericEntityException e) {
170: Debug.logError(
171: "[UIDisplayObjectWebEventProcessor.postInsert] Error looking for original "
172: + "screen section entities: "
173: + e.getLocalizedMessage(), module);
174: }
175:
176: //////////
177: // Copy all the screen section infos (fields) from the original screen section.
178: //////////
179: HashMap uiScreenSectionInfoFindMap = new HashMap();
180: uiScreenSectionInfoFindMap.put("sectionId", sectionIdOrig);
181:
182: try {
183: // Get the List of original screen section infos.
184: List uiScreenSectionInfoGVLOrig = delegator.findByAnd(
185: "UiScreenSectionInfo",
186: uiScreenSectionInfoFindMap);
187: Iterator uiScreenSectionInfoGVIOrig = uiScreenSectionInfoGVLOrig
188: .iterator();
189: ModelEntity uiScreenSectionInfoME = delegator
190: .getModelEntity("UiScreenSectionInfo");
191:
192: while (uiScreenSectionInfoGVIOrig.hasNext()) {
193: GenericValue uiScreenSectionInfoGVOrig = (GenericValue) uiScreenSectionInfoGVIOrig
194: .next();
195: String partyIdOrig = (uiScreenSectionInfoGVOrig
196: .getString("partyId") == null) ? ""
197: : uiScreenSectionInfoGVOrig
198: .getString("partyId");
199: String attributeIdOrig = (uiScreenSectionInfoGVOrig
200: .getString("attributeId") == null) ? ""
201: : uiScreenSectionInfoGVOrig
202: .getString("attributeId");
203:
204: // Get values from the original screen section info.
205: String displayObjectIdOrig = (uiScreenSectionInfoGVOrig
206: .getString("displayObjectId") == null) ? ""
207: : uiScreenSectionInfoGVOrig
208: .getString("displayObjectId");
209: String maxLengthOrig = (uiScreenSectionInfoGVOrig
210: .getString("maxLength") == null) ? ""
211: : uiScreenSectionInfoGVOrig
212: .getString("maxLength");
213: String isMandatoryOrig = (uiScreenSectionInfoGVOrig
214: .getString("isMandatory") == null) ? ""
215: : uiScreenSectionInfoGVOrig
216: .getString("isMandatory");
217: String isReadOnlyOrig = (uiScreenSectionInfoGVOrig
218: .getString("isReadOnly") == null) ? ""
219: : uiScreenSectionInfoGVOrig
220: .getString("isReadOnly");
221: String isVisibleOrig = (uiScreenSectionInfoGVOrig
222: .getString("isVisible") == null) ? ""
223: : uiScreenSectionInfoGVOrig
224: .getString("isVisible");
225: String isSearchableOrig = (uiScreenSectionInfoGVOrig
226: .getString("isSearchable") == null) ? ""
227: : uiScreenSectionInfoGVOrig
228: .getString("isSearchable");
229: String displayOrderOrig = (uiScreenSectionInfoGVOrig
230: .getString("displayOrder") == null) ? ""
231: : uiScreenSectionInfoGVOrig
232: .getString("displayOrder");
233: String displayLabelOrig = (uiScreenSectionInfoGVOrig
234: .getString("displayLabel") == null) ? ""
235: : uiScreenSectionInfoGVOrig
236: .getString("displayLabel");
237: String displayLengthOrig = (uiScreenSectionInfoGVOrig
238: .getString("displayLength") == null) ? ""
239: : uiScreenSectionInfoGVOrig
240: .getString("displayLength");
241: String colSpanOrig = (uiScreenSectionInfoGVOrig
242: .getString("colSpan") == null) ? ""
243: : uiScreenSectionInfoGVOrig
244: .getString("colSpan");
245: String rowSpanOrig = (uiScreenSectionInfoGVOrig
246: .getString("rowSpan") == null) ? ""
247: : uiScreenSectionInfoGVOrig
248: .getString("rowSpan");
249: String startOnNewRowOrig = (uiScreenSectionInfoGVOrig
250: .getString("startOnNewRow") == null) ? ""
251: : uiScreenSectionInfoGVOrig
252: .getString("startOnNewRow");
253:
254: // Create the new screen section entity using the new section ID.
255: GenericValue uiScreenSectionInfoGV = new GenericValue(
256: uiScreenSectionInfoME);
257: uiScreenSectionInfoGV.setDelegator(delegator);
258: uiScreenSectionInfoGV.set("sectionId", sectionId);
259: uiScreenSectionInfoGV.set("partyId", partyIdOrig);
260: uiScreenSectionInfoGV.set("attributeId",
261: attributeIdOrig);
262: uiScreenSectionInfoGV.set("displayObjectId",
263: displayObjectIdOrig);
264: uiScreenSectionInfoGV.set("maxLength", Long
265: .valueOf(maxLengthOrig));
266: uiScreenSectionInfoGV.set("isMandatory",
267: isMandatoryOrig);
268: uiScreenSectionInfoGV.set("isReadOnly",
269: isReadOnlyOrig);
270: uiScreenSectionInfoGV.set("isVisible",
271: isVisibleOrig);
272: uiScreenSectionInfoGV.set("isSearchable",
273: isSearchableOrig);
274: uiScreenSectionInfoGV.set("displayOrder", Long
275: .valueOf(displayOrderOrig));
276: uiScreenSectionInfoGV.set("displayLabel",
277: displayLabelOrig);
278: uiScreenSectionInfoGV.set("displayLength", Long
279: .valueOf(displayLengthOrig));
280: uiScreenSectionInfoGV.set("colSpan", Long
281: .valueOf(colSpanOrig));
282: uiScreenSectionInfoGV.set("rowSpan", Long
283: .valueOf(rowSpanOrig));
284: uiScreenSectionInfoGV.set("startOnNewRow",
285: startOnNewRowOrig);
286:
287: delegator.create(uiScreenSectionInfoGV);
288: }
289: } catch (GenericEntityException e) {
290: Debug.logError(
291: "[UIDisplayObjectWebEventProcessor.postInsert] Error looking for original "
292: + "screen section infos: "
293: + e.getLocalizedMessage(), module);
294: }
295: }
296:
297: return STATUS_CONTINUE;
298: }
299:
300: /**
301: * DOCUMENT ME!
302: *
303: * @param userInfo
304: * @param delegator
305: * @param originatingEntityName
306: * @param entityGV
307: *
308: * @return
309: */
310: public int deleteAllRelated(UserInfo userInfo,
311: GenericDelegator delegator, String originatingEntityName,
312: GenericValue entityGV) {
313:
314: int status = STATUS_CONTINUE;
315:
316: // Delete related screen section entities.
317: status = deleteOneRelated(userInfo, delegator, entityGV, "",
318: "UiScreenSectionEntity", originatingEntityName,
319: new GenericEventProcessor());
320:
321: // Delete related screen section infos (fields).
322: status = deleteOneRelated(userInfo, delegator, entityGV, "",
323: "UiScreenSectionInfo", originatingEntityName,
324: new GenericEventProcessor());
325:
326: return status;
327: }
328: }
|