001: /*
002: * $Id: StatusWorker.java,v 1.1 2003/08/17 10:12:40 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.common.status;
026:
027: import java.util.Collection;
028: import java.util.LinkedList;
029: import java.util.List;
030:
031: import javax.servlet.jsp.PageContext;
032:
033: import org.ofbiz.base.util.Debug;
034: import org.ofbiz.base.util.UtilMisc;
035: import org.ofbiz.entity.GenericDelegator;
036: import org.ofbiz.entity.GenericEntityException;
037:
038: /**
039: * StatusWorker
040: *
041: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
042: * @version $Revision: 1.1 $
043: * @since 2.0
044: */
045: public class StatusWorker {
046:
047: public static final String module = StatusWorker.class.getName();
048:
049: public static void getStatusItems(PageContext pageContext,
050: String attributeName, String statusTypeId) {
051: GenericDelegator delegator = (GenericDelegator) pageContext
052: .getRequest().getAttribute("delegator");
053:
054: try {
055: Collection statusItems = delegator.findByAndCache(
056: "StatusItem", UtilMisc.toMap("statusTypeId",
057: statusTypeId), UtilMisc
058: .toList("sequenceId"));
059:
060: if (statusItems != null)
061: pageContext.setAttribute(attributeName, statusItems);
062: } catch (GenericEntityException e) {
063: Debug.logError(e, module);
064: }
065: }
066:
067: public static void getStatusItems(PageContext pageContext,
068: String attributeName, String statusTypeIdOne,
069: String statusTypeIdTwo) {
070: GenericDelegator delegator = (GenericDelegator) pageContext
071: .getRequest().getAttribute("delegator");
072: List statusItems = new LinkedList();
073:
074: try {
075: Collection calItems = delegator.findByAndCache(
076: "StatusItem", UtilMisc.toMap("statusTypeId",
077: statusTypeIdOne), UtilMisc
078: .toList("sequenceId"));
079:
080: if (calItems != null)
081: statusItems.addAll(calItems);
082: } catch (GenericEntityException e) {
083: Debug.logError(e, module);
084: }
085: try {
086: Collection taskItems = delegator.findByAndCache(
087: "StatusItem", UtilMisc.toMap("statusTypeId",
088: statusTypeIdTwo), UtilMisc
089: .toList("sequenceId"));
090:
091: if (taskItems != null)
092: statusItems.addAll(taskItems);
093: } catch (GenericEntityException e) {
094: Debug.logError(e, module);
095: }
096:
097: if (statusItems.size() > 0)
098: pageContext.setAttribute(attributeName, statusItems);
099: }
100:
101: public static void getStatusValidChangeToDetails(
102: PageContext pageContext, String attributeName,
103: String statusId) {
104: GenericDelegator delegator = (GenericDelegator) pageContext
105: .getRequest().getAttribute("delegator");
106: Collection statusValidChangeToDetails = null;
107:
108: try {
109: statusValidChangeToDetails = delegator.findByAndCache(
110: "StatusValidChangeToDetail", UtilMisc.toMap(
111: "statusId", statusId), UtilMisc
112: .toList("sequenceId"));
113: } catch (GenericEntityException e) {
114: Debug.logError(e, module);
115: }
116:
117: if (statusValidChangeToDetails != null)
118: pageContext.setAttribute(attributeName,
119: statusValidChangeToDetails);
120: }
121: }
|