KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > manufacturing > routing > RoutingServices


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

23 package org.ofbiz.manufacturing.routing;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.Locale JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.ofbiz.base.util.UtilMisc;
30 import org.ofbiz.entity.GenericDelegator;
31 import org.ofbiz.entity.GenericEntityException;
32 import org.ofbiz.entity.GenericValue;
33 import org.ofbiz.service.DispatchContext;
34 import org.ofbiz.service.LocalDispatcher;
35 import org.ofbiz.service.ServiceUtil;
36
37 import org.ofbiz.manufacturing.jobshopmgt.ProductionRun;
38
39 /**
40  * Routing related services
41  *
42  * @author <a HREF="mailto:tiz@sastau.it">Jacopo Cappellato</a>
43  */

44 public class RoutingServices {
45     
46     public static final String JavaDoc module = RoutingServices.class.getName();
47     public static final String JavaDoc resource = "ManufacturingUiLabels";
48     
49     /**
50      * Computes the estimated time needed to perform the task.
51      * @param ctx The DispatchContext that this service is operating in.
52      * @param context Map containing the input parameters.
53      * @return Map with the result of the service, the output parameters.
54      */

55     public static Map JavaDoc getEstimatedTaskTime(DispatchContext ctx, Map JavaDoc context) {
56         Map JavaDoc result = new HashMap JavaDoc();
57         GenericDelegator delegator = ctx.getDelegator();
58         LocalDispatcher dispatcher = ctx.getDispatcher();
59         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
60         GenericValue userLogin = (GenericValue) context.get("userLogin");
61         
62         // The mandatory IN parameters
63
String JavaDoc taskId = (String JavaDoc) context.get("taskId");
64         Double JavaDoc quantity = (Double JavaDoc) context.get("quantity");
65         // The optional IN parameters
66
String JavaDoc productId = (String JavaDoc) context.get("productId");
67         String JavaDoc routingId = (String JavaDoc) context.get("routingId");
68         
69         if (quantity == null) {
70             quantity = new Double JavaDoc(1);
71         }
72
73         GenericValue task = null;
74         try {
75             task = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", taskId));
76         } catch(GenericEntityException gee) {
77             ServiceUtil.returnError("Error finding routing task with id: " + taskId);
78         }
79         // FIXME: the ProductionRun.getEstimatedTaskTime(...) method will be removed and
80
// its logic will be implemented inside this method.
81
long estimatedTaskTime = ProductionRun.getEstimatedTaskTime(task, quantity, productId, routingId, dispatcher);
82         result.put("estimatedTaskTime", new Long JavaDoc(estimatedTaskTime));
83         if (task != null && task.get("estimatedSetupMillis") != null) {
84             result.put("setupTime", task.getDouble("estimatedSetupMillis"));
85         }
86         if (task != null && task.get("estimatedMilliSeconds") != null) {
87             result.put("taskUnitTime", task.getDouble("estimatedMilliSeconds"));
88         }
89         return result;
90     }
91 }
92
Popular Tags