KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shipment > packing > PackingSessionLine


1 /*
2  * $Id$
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.shipment.packing;
26
27 import java.util.Map JavaDoc;
28
29 import org.ofbiz.service.LocalDispatcher;
30 import org.ofbiz.service.ServiceUtil;
31 import org.ofbiz.entity.GenericValue;
32 import org.ofbiz.base.util.GeneralException;
33 import org.ofbiz.base.util.UtilFormatOut;
34 import javolution.util.FastMap;
35
36 /**
37  *
38  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
39  * @version $Rev: 5724 $
40  * @since Sep 1, 2005
41  */

42 public class PackingSessionLine implements java.io.Serializable JavaDoc {
43
44     public final String JavaDoc module = PackingSessionLine.class.getName();
45
46     protected String JavaDoc orderId = null;
47     protected String JavaDoc orderItemSeqId = null;
48     protected String JavaDoc shipGroupSeqId = null;
49     protected String JavaDoc productId = null;
50     protected String JavaDoc inventoryItemId = null;
51     protected String JavaDoc shipmentItemSeqId = null;
52     protected double quantity = 0;
53     protected int packageSeq = 0;
54
55     public PackingSessionLine(String JavaDoc orderId, String JavaDoc orderItemSeqId, String JavaDoc shipGroupSeqId, String JavaDoc productId, String JavaDoc inventoryItemId, double quantity, int packageSeq) {
56         this.orderId = orderId;
57         this.orderItemSeqId = orderItemSeqId;
58         this.shipGroupSeqId = shipGroupSeqId;
59         this.inventoryItemId = inventoryItemId;
60         this.productId = productId;
61         this.quantity = quantity;
62         this.packageSeq = packageSeq;
63     }
64
65     public String JavaDoc getOrderId() {
66         return this.orderId;
67     }
68
69     public String JavaDoc getOrderItemSeqId() {
70         return this.orderItemSeqId;
71     }
72
73     public String JavaDoc getShipGroupSeqId() {
74         return this.shipGroupSeqId;
75     }
76
77     public String JavaDoc getInventoryItemId() {
78         return this.inventoryItemId;
79     }
80
81     public String JavaDoc getProductId() {
82         return this.productId;
83     }
84
85     public String JavaDoc getShipmentItemSeqId() {
86         return this.shipmentItemSeqId;
87     }
88
89     public void setShipmentItemSeqId(String JavaDoc shipmentItemSeqId) {
90         this.shipmentItemSeqId = shipmentItemSeqId;
91     }
92
93     public double getQuantity() {
94         return this.quantity;
95     }
96
97     public void setQuantity(double quantity) {
98         this.quantity = quantity;
99     }
100
101     public void addQuantity(double quantity) {
102         this.quantity += quantity;
103     }
104
105     public int getPackageSeq() {
106         return this.packageSeq;
107     }
108
109     protected void issueItemToShipment(String JavaDoc shipmentId, GenericValue userLogin, LocalDispatcher dispatcher) throws GeneralException {
110         Map JavaDoc issueMap = FastMap.newInstance();
111         issueMap.put("shipmentId", shipmentId);
112         issueMap.put("orderId", this.getOrderId());
113         issueMap.put("orderItemSeqId", this.getOrderItemSeqId());
114         issueMap.put("shipGroupSeqId", this.getShipGroupSeqId());
115         issueMap.put("inventoryItemId", this.getInventoryItemId());
116         issueMap.put("quantity", new Double JavaDoc(this.getQuantity()));
117         issueMap.put("userLogin", userLogin);
118
119         Map JavaDoc issueResp = dispatcher.runSync("issueOrderItemShipGrpInvResToShipment", issueMap);
120         if (ServiceUtil.isError(issueResp)) {
121             throw new GeneralException(ServiceUtil.getErrorMessage(issueResp));
122         }
123
124         String JavaDoc shipmentItemSeqId = (String JavaDoc) issueResp.get("shipmentItemSeqId");
125         if (shipmentItemSeqId == null) {
126             throw new GeneralException("Issue item did not return a valid shipmentItemSeqId!");
127         } else {
128             this.setShipmentItemSeqId(shipmentItemSeqId);
129         }
130     }
131
132     protected void applyLineToPackage(String JavaDoc shipmentId, GenericValue userLogin, LocalDispatcher dispatcher) throws GeneralException {
133         // assign item to package
134
String JavaDoc shipmentPackageSeqId = UtilFormatOut.formatPaddedNumber(this.getPackageSeq(), 5);
135
136         Map JavaDoc packageMap = FastMap.newInstance();
137         packageMap.put("shipmentId", shipmentId);
138         packageMap.put("shipmentItemSeqId", this.getShipmentItemSeqId());
139         packageMap.put("quantity", new Double JavaDoc(this.getQuantity()));
140         packageMap.put("shipmentPackageSeqId", shipmentPackageSeqId);
141         packageMap.put("userLogin", userLogin);
142         Map JavaDoc packageResp = dispatcher.runSync("addShipmentContentToPackage", packageMap);
143
144         if (ServiceUtil.isError(packageResp)) {
145             throw new GeneralException(ServiceUtil.getErrorMessage(packageResp));
146         }
147     }
148 }
149
Popular Tags