KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MProjectPhase


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.sql.*;
17 import java.util.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Project Phase Model
23  *
24  * @author Jorg Janke
25  * @version $Id: MProjectPhase.java,v 1.4 2003/08/25 02:31:57 jjanke Exp $
26  */

27 public class MProjectPhase extends X_C_ProjectPhase
28 {
29     public MProjectPhase (Properties ctx, int C_ProjectPhase_ID)
30     {
31         super (ctx, C_ProjectPhase_ID);
32         if (C_ProjectPhase_ID == 0)
33         {
34         // setC_ProjectPhase_ID (0); // PK
35
// setC_Project_ID (0); // Parent
36
// setC_Phase_ID (0); // FK
37
setCommittedAmt (Env.ZERO);
38             setIsCommitCeiling (false);
39             setIsComplete (false);
40             setSeqNo (0);
41         // setName (null);
42
setQty (Env.ZERO);
43         }
44     } // MProjectPhase
45

46     public MProjectPhase (Properties ctx, ResultSet rs)
47     {
48         super (ctx, rs);
49     } // MProjectPhase
50

51     public MProjectPhase (Properties ctx, int C_Project_ID, MProjectTypePhase phase)
52     {
53         super (ctx, 0);
54         setC_Project_ID (C_Project_ID); // Parent
55
setCommittedAmt (Env.ZERO);
56         setIsCommitCeiling (false);
57         setIsComplete (false);
58         //
59
setC_Phase_ID (phase.getC_Phase_ID()); // FK
60
setName (phase.getName());
61         setSeqNo (phase.getSeqNo());
62         setDescription(phase.getDescription());
63         setHelp(phase.getHelp());
64         if (phase.getM_Product_ID() != 0)
65             setM_Product_ID(phase.getM_Product_ID());
66         setQty(phase.getStandardQty());
67     } // MProjectPhase
68

69     /**
70      * Get Project Phase Tasks.
71      * @return Array of tasks
72      */

73     public MProjectTask[] getTasks()
74     {
75         ArrayList list = new ArrayList();
76         String JavaDoc sql = "SELECT * FROM C_ProjectTask WHERE C_ProjectPhase_ID=? ORDER BY SeqNo";
77         PreparedStatement pstmt = null;
78         try
79         {
80             pstmt = DB.prepareStatement(sql);
81             pstmt.setInt(1, getC_ProjectPhase_ID());
82             ResultSet rs = pstmt.executeQuery();
83             while (rs.next())
84                 list.add(new MProjectTask (getCtx(), rs));
85             rs.close();
86             pstmt.close();
87             pstmt = null;
88         }
89         catch (SQLException ex)
90         {
91             log.error("getTasks", ex);
92         }
93         try
94         {
95             if (pstmt != null)
96                 pstmt.close();
97         }
98         catch (SQLException ex1)
99         {
100         }
101         pstmt = null;
102         //
103
MProjectTask[] retValue = new MProjectTask[list.size()];
104         list.toArray(retValue);
105         return retValue;
106     } // getTasks
107

108
109     /**
110      * Copy Tasks from other Phase
111      * @param fromPhase from phase
112      * @return number of tasks copied
113      */

114     public int copyTasksFrom (MProjectPhase fromPhase)
115     {
116         if (fromPhase == null)
117             return 0;
118         int count = 0;
119         //
120
MProjectTask[] myTasks = getTasks();
121         MProjectTask[] fromTasks = fromPhase.getTasks();
122         // Copy Project Tasks
123
for (int i = 0; i < fromTasks.length; i++)
124         {
125             // Check if Task already exists
126
int C_Task_ID = fromTasks[i].getC_Task_ID();
127             boolean exists = false;
128             if (C_Task_ID == 0)
129                 exists = false;
130             else
131             {
132                 for (int ii = 0; ii < myTasks.length; ii++)
133                 {
134                     if (myTasks[ii].getC_Task_ID() == C_Task_ID)
135                     {
136                         exists = true;
137                         break;
138                     }
139                 }
140             }
141             // Phase exist
142
if (exists)
143                 log.info("copyTasksFrom - Task already exists here, ignored - " + fromTasks[i]);
144             else
145             {
146                 MProjectTask toTask = new MProjectTask (getCtx (), 0);
147                 PO.copyValues (fromTasks[i], toTask, getAD_Client_ID (), getAD_Org_ID ());
148                 toTask.setC_ProjectPhase_ID (getC_ProjectPhase_ID ());
149                 if (toTask.save ())
150                     count++;
151             }
152         }
153         if (fromTasks.length != count)
154             log.warn("copyTasksFrom - Count difference - ProjectPhase=" + fromTasks.length + " <> Saved=" + count);
155
156         return count;
157     } // copyTasksFrom
158

159     /**
160      * Copy Tasks from other Phase
161      * @param fromPhase from phase
162      * @return number of tasks copied
163      */

164     public int copyTasksFrom (MProjectTypePhase fromPhase)
165     {
166         if (fromPhase == null)
167             return 0;
168         int count = 0;
169         // Copy Type Tasks
170
MProjectTypeTask[] fromTasks = fromPhase.getTasks();
171         for (int i = 0; i < fromTasks.length; i++)
172         {
173             MProjectTask toTask = new MProjectTask (getCtx(), getC_ProjectPhase_ID(), fromTasks[i]);
174             if (toTask.save())
175                 count++;
176         }
177         if (fromTasks.length != count)
178             log.error("copyTasksFrom - Count difference - TypePhase=" + fromTasks.length + " <> Saved=" + count);
179
180         return count;
181     } // copyTasksFrom
182

183 } // MProjectPhase
184
Popular Tags