001: /*
002: * $Id: StatusServices.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.HashMap;
029: import java.util.Iterator;
030: import java.util.LinkedList;
031: import java.util.List;
032: import java.util.Map;
033:
034: import org.ofbiz.base.util.Debug;
035: import org.ofbiz.base.util.UtilMisc;
036: import org.ofbiz.entity.GenericDelegator;
037: import org.ofbiz.entity.GenericEntityException;
038: import org.ofbiz.service.DispatchContext;
039: import org.ofbiz.service.ServiceUtil;
040:
041: /**
042: * StatusServices
043: *
044: * @author <a href="mailto:johan@ibibi.com">Johan Isacsson</a>
045: * @version $Revision: 1.1 $
046: * @since 2.1
047: */
048: public class StatusServices {
049:
050: public static final String module = StatusServices.class.getName();
051:
052: public static Map getStatusItems(DispatchContext ctx, Map context) {
053: GenericDelegator delegator = (GenericDelegator) ctx
054: .getDelegator();
055: List statusTypes = (List) context.get("statusTypeIds");
056: if (statusTypes == null || statusTypes.size() == 0) {
057: return ServiceUtil
058: .returnError("Parameter statusTypeIds can not be null and must contain at least one element");
059: }
060:
061: Iterator i = statusTypes.iterator();
062: List statusItems = new LinkedList();
063: while (i.hasNext()) {
064: String statusTypeId = (String) i.next();
065: try {
066: Collection myStatusItems = delegator.findByAndCache(
067: "StatusItem", UtilMisc.toMap("statusTypeId",
068: statusTypeId), UtilMisc
069: .toList("sequenceId"));
070: statusItems.addAll(myStatusItems);
071: } catch (GenericEntityException e) {
072: Debug.logError(e, module);
073: }
074: }
075: Map ret = new HashMap();
076: ret.put("statusItems", statusItems);
077: return ret;
078: }
079:
080: public static Map getStatusValidChangeToDetails(
081: DispatchContext ctx, Map context) {
082: GenericDelegator delegator = (GenericDelegator) ctx
083: .getDelegator();
084:
085: Collection statusValidChangeToDetails = null;
086: String statusId = (String) context.get("statusTypeId");
087:
088: try {
089: statusValidChangeToDetails = delegator.findByAndCache(
090: "StatusValidChangeToDetail", UtilMisc.toMap(
091: "statusId", statusId), UtilMisc
092: .toList("sequenceId"));
093: } catch (GenericEntityException e) {
094: Debug.logError(e, module);
095: }
096:
097: Map ret = new HashMap();
098: if (statusValidChangeToDetails != null)
099: ret.put("statusValidChangeToDetail",
100: statusValidChangeToDetails);
101: return ret;
102: }
103: }
|