KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > manufacturing > jobshopmgt > ProductionRunHelper


1 /*
2  * $Id: ProductionRunHelper.java 7238 2006-04-08 07:30:54Z jacopo $
3  *
4  * Copyright (c) 2004 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.manufacturing.jobshopmgt;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.base.util.UtilMisc;
33 import org.ofbiz.entity.GenericDelegator;
34 import org.ofbiz.entity.GenericEntityException;
35 import org.ofbiz.entity.GenericValue;
36 import org.ofbiz.entity.util.EntityUtil;
37 import org.ofbiz.service.LocalDispatcher;
38
39
40 /**
41  * Helper for Production Run maintenance
42  *
43  * @author <a HREF="mailto:olivier.heintz@nereide.biz">Olivier Heintz</a>
44  */

45 public class ProductionRunHelper {
46     
47     public static final String JavaDoc module = ProductionRunHelper.class.getName();
48     public static final String JavaDoc resource = "ManufacturingUiLabels";
49     
50     
51     /**
52      * Get a Production Run.
53      * <li> check if routing - product link exist
54      * @param ctx The DispatchContext that this service is operating in.
55      * @param context Map containing the input parameters, productionRunId
56      * @return Map with the result of the service, the output parameters are
57      * <li> the productionRun
58      * <li> the productionRunProduct
59      */

60     public static Map JavaDoc getProductionRun(GenericDelegator delegator, String JavaDoc productionRunId) {
61         Map JavaDoc result = new HashMap JavaDoc();
62         // Timestamp now = UtilDateTime.nowTimestamp();
63

64         try {
65             if (productionRunId != null ) {
66                 GenericValue productionRun = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", productionRunId));
67                 if (productionRun != null) {
68                     List JavaDoc productionRunProducts = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV"),null);
69                     GenericValue productionRunProduct = EntityUtil.getFirst(productionRunProducts);
70                     GenericValue productProduced = productionRunProduct.getRelatedOneCache("Product");
71                     List JavaDoc productionRunComponents = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"),null);
72                     List JavaDoc productionRunRoutingTasks = productionRun.getRelated("FromWorkEffortAssoc",UtilMisc.toMap("workEffortTypeId","PROD_ORDER_TASK"),null);
73                     
74                 }
75             }
76         } catch (GenericEntityException e) {
77             Debug.logWarning(e.getMessage(), module);
78         }
79         return result;
80     }
81
82     public static boolean hasTask(GenericDelegator delegator, String JavaDoc taskName, String JavaDoc workEffortId) throws GenericEntityException {
83         List JavaDoc tasks = delegator.findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", workEffortId,
84                                                          "workEffortTypeId", "PROD_ORDER_TASK",
85                                                          "workEffortName", taskName));
86         return (tasks != null && tasks.size() > 0);
87     }
88
89     public static void getLinkedProductionRuns(GenericDelegator delegator, LocalDispatcher dispatcher, String JavaDoc productionRunId, List JavaDoc productionRuns) throws GenericEntityException {
90         productionRuns.add(new ProductionRun(productionRunId, delegator, dispatcher));
91         List JavaDoc linkedWorkEfforts = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdTo", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY")));
92         for (int i = 0; i < linkedWorkEfforts.size(); i++) {
93             GenericValue link = (GenericValue)linkedWorkEfforts.get(i);
94             getLinkedProductionRuns(delegator, dispatcher, link.getString("workEffortIdFrom"), productionRuns);
95         }
96     }
97
98     public static String JavaDoc getRootProductionRun(GenericDelegator delegator, String JavaDoc productionRunId) throws GenericEntityException {
99         List JavaDoc linkedWorkEfforts = delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdFrom", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY"));
100         GenericValue linkedWorkEffort = EntityUtil.getFirst(linkedWorkEfforts);
101         if (linkedWorkEffort != null) {
102             productionRunId = getRootProductionRun(delegator, linkedWorkEffort.getString("workEffortIdTo"));
103         }
104         return productionRunId;
105     }
106
107 }
108
Popular Tags