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 com.sourcetap.sfa.event.GenericEventProcessor;
020:
021: import org.ofbiz.entity.*;
022: import org.ofbiz.entity.model.ModelEntity;
023:
024: import java.util.*;
025:
026: /**
027: * DOCUMENT ME!
028: *
029: */
030: public class UIScreenEventProcessor extends GenericEventProcessor {
031: private static final boolean DEBUG = false;
032:
033: // Define function to get all entities (screen section entities) associated with a section.
034: protected Iterator getUiScreenSectionEntityIterator(
035: String sectionId, GenericDelegator delegator)
036: throws GenericEntityException {
037: HashMap uiScreenSectionEntityMap = new HashMap();
038: uiScreenSectionEntityMap.put("sectionId", sectionId);
039:
040: ArrayList order = new ArrayList();
041: order.add("entityId");
042:
043: List uiScreenSectionEntitys = delegator.findByAnd(
044: "UiScreenSectionEntity", uiScreenSectionEntityMap,
045: order);
046:
047: return uiScreenSectionEntitys.iterator();
048: }
049:
050: // Define function to get all attributes (screen section infos) associated with a section.
051: protected Iterator getUiScreenSectionInfoIterator(String sectionId,
052: GenericDelegator delegator) throws GenericEntityException {
053: HashMap uiScreenSectionInfoMap = new HashMap();
054: uiScreenSectionInfoMap.put("sectionId", sectionId);
055:
056: ArrayList order = new ArrayList();
057: order.add("partyId");
058: order.add("displayOrder");
059:
060: List uiScreenSectionInfos = delegator.findByAnd(
061: "UiScreenSectionInfo", uiScreenSectionInfoMap, order);
062:
063: return uiScreenSectionInfos.iterator();
064: }
065:
066: // Define function to add missing eligible attributes.
067: public void addMissingAttributes(String sectionId,
068: GenericDelegator delegator, String partyId)
069: throws GenericEntityException {
070: ModelEntity uiScreenSectionInfoEntity = delegator
071: .getModelEntity("UiScreenSectionInfo");
072:
073: // Get the entities associated with this screen section.
074: Iterator uiScreenSectionEntityIterator2 = getUiScreenSectionEntityIterator(
075: sectionId, delegator);
076:
077: // Loop through entities associated with this screen section.
078: while (uiScreenSectionEntityIterator2.hasNext()) {
079: GenericValue uiScreenSectionEntityDetails = (GenericValue) uiScreenSectionEntityIterator2
080: .next();
081:
082: // Get the attributes associated with this entity.
083: HashMap uiAttributeMap = new HashMap();
084: uiAttributeMap.put("entityId", uiScreenSectionEntityDetails
085: .getString("entityId"));
086:
087: List uiAttributes = delegator.findByAnd("UiAttribute",
088: uiAttributeMap, null);
089: Iterator uiAttributeIterator2 = uiAttributes.iterator();
090:
091: // Loop through all eligible attributes for this entity.
092: while (uiAttributeIterator2.hasNext()) {
093: GenericValue uiAttributeDetails = (GenericValue) uiAttributeIterator2
094: .next();
095: boolean attributeFound = false;
096:
097: // Get the attributes associated with this screen section.
098: Iterator uiScreenSectionInfoIterator2 = getUiScreenSectionInfoIterator(
099: sectionId, delegator);
100:
101: // Loop through the already associated attributes to see if this on is already associated with the section
102: // for the specified party ID.
103: while (uiScreenSectionInfoIterator2.hasNext()) {
104: GenericValue uiScreenSectionInfoDetails = (GenericValue) uiScreenSectionInfoIterator2
105: .next();
106:
107: // See if this is a match.
108: if (uiScreenSectionInfoDetails.getString(
109: "attributeId")
110: .equals(
111: uiAttributeDetails
112: .getString("attributeId"))
113: && uiScreenSectionInfoDetails.getString(
114: "partyId").equals(partyId)) {
115: // This is a match. We don't need to add this one.
116: attributeFound = true;
117: }
118: }
119:
120: // Clear the screen section info iterator so we can loop through it again.
121: uiScreenSectionInfoIterator2 = null;
122:
123: if (!attributeFound) {
124: // This eligible attribute is not associated with the screen section for this party ID. Add it.
125: GenericValue newUiScreenSectionInfoDetails = new GenericValue(
126: uiScreenSectionInfoEntity);
127: newUiScreenSectionInfoDetails
128: .setDelegator(delegator);
129: newUiScreenSectionInfoDetails.set("sectionId",
130: sectionId);
131: newUiScreenSectionInfoDetails.set("partyId",
132: partyId);
133: newUiScreenSectionInfoDetails.set(
134: "displayObjectId", uiAttributeDetails
135: .getString("displayObjectId"));
136: newUiScreenSectionInfoDetails
137: .set("attributeId", uiAttributeDetails
138: .getString("attributeId"));
139: newUiScreenSectionInfoDetails.set("maxLength",
140: uiAttributeDetails.getString("maxLength"));
141: newUiScreenSectionInfoDetails
142: .set("isMandatory", uiAttributeDetails
143: .getString("isMandatory"));
144: newUiScreenSectionInfoDetails.set("isReadOnly",
145: uiAttributeDetails.getString("isReadOnly"));
146: newUiScreenSectionInfoDetails.set("isVisible",
147: uiAttributeDetails.getString("isVisible"));
148: newUiScreenSectionInfoDetails.set("isSearchable",
149: uiAttributeDetails
150: .getString("isSearchable"));
151: newUiScreenSectionInfoDetails.set("displayOrder",
152: uiAttributeDetails
153: .getString("displayOrder"));
154: newUiScreenSectionInfoDetails.set("displayLabel",
155: uiAttributeDetails
156: .getString("displayLabel"));
157: newUiScreenSectionInfoDetails.set("displayLength",
158: uiAttributeDetails
159: .getString("displayLength"));
160: newUiScreenSectionInfoDetails.set("rowSpan",
161: uiAttributeDetails.getString("rowSpan"));
162: newUiScreenSectionInfoDetails.set("colSpan",
163: uiAttributeDetails.getString("colSpan"));
164: delegator.create(newUiScreenSectionInfoDetails);
165: }
166: }
167: }
168: }
169: }
|