KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > process > DocumentTypeVerify


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 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.process;
15
16 import java.sql.*;
17 import java.math.*;
18
19 import org.compiere.model.*;
20 import org.compiere.util.*;
21
22 /**
23  * Verify Document Types.
24  * - Make sure that there is a DocumentType for all Document Base Types
25  * - Create missing Period Controls for Document Type
26  *
27  * @author Jorg Janke
28  * @version $Id: DocumentTypeVerify.java,v 1.2 2003/10/13 03:59:49 jjanke Exp $
29  */

30 public class DocumentTypeVerify extends SvrProcess
31 {
32
33     /**
34      * No Parameters (Nop)
35      * @see org.compiere.process.SvrProcess#prepare()
36      */

37     protected void prepare()
38     {
39     } // prepare
40

41     /**
42      * Execute process
43      * @see org.compiere.process.SvrProcess#doIt()
44      * @return info
45      * @throws Exception
46      */

47     protected String JavaDoc doIt() throws Exception JavaDoc
48     {
49         createDocumentTypes();
50         createPeriodControls();
51         return "";
52     } // doIt
53

54     /**
55      * Create Missing Document Types
56      */

57     private void createDocumentTypes()
58     {
59         String JavaDoc sql = "SELECT rl.Value, rl.Name "
60             + "FROM AD_Ref_List rl "
61             + "WHERE rl.AD_Reference_ID=183"
62             + " AND rl.IsActive='Y' AND NOT EXISTS"
63             + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)";
64         PreparedStatement pstmt = null;
65         try
66         {
67             pstmt = DB.prepareCall(sql);
68             pstmt.setInt(1, getAD_Client_ID());
69             ResultSet rs = pstmt.executeQuery();
70             while (rs.next())
71             {
72                 String JavaDoc name = rs.getString(2);
73                 MDocType dt = new MDocType (getCtx(), rs.getString(1), name);
74                 if (dt.save())
75                     addLog (0, null, null, name);
76                 else
77                     addLog (0, null, null, "Not created: " + name);
78             }
79             rs.close();
80             pstmt.close();
81             pstmt = null;
82         }
83         catch (Exception JavaDoc e)
84         {
85             log.error("createDocumentTypes", e);
86         }
87         try
88         {
89             if (pstmt != null)
90                 pstmt.close();
91             pstmt = null;
92         }
93         catch (Exception JavaDoc e)
94         {
95             pstmt = null;
96         }
97     } // createDocumentTypes
98

99     /**
100      * Create Period Controls
101      */

102     private void createPeriodControls()
103     {
104         String JavaDoc sql = "SELECT p.C_Period_ID, dt.DocBaseType "
105             + "FROM C_Period p"
106             + " FULL JOIN C_DocType dt ON (p.AD_Client_ID=dt.AD_Client_ID) "
107             + "WHERE p.AD_Client_ID=?"
108             + " AND NOT EXISTS"
109             + " (SELECT * FROM C_PeriodControl pc WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dt.DocBaseType)";
110         PreparedStatement pstmt = null;
111         int counter = 0;
112         try
113         {
114             pstmt = DB.prepareCall(sql);
115             pstmt.setInt(1, getAD_Client_ID());
116             ResultSet rs = pstmt.executeQuery();
117             while (rs.next())
118             {
119                 MPeriodControl pc = new MPeriodControl (getCtx(), rs.getInt(1), rs.getString(2));
120                 if (pc.save())
121                     counter++;
122             }
123             rs.close();
124             pstmt.close();
125             pstmt = null;
126         }
127         catch (Exception JavaDoc e)
128         {
129             log.error("createPeriodControls", e);
130         }
131         try
132         {
133             if (pstmt != null)
134                 pstmt.close();
135             pstmt = null;
136         }
137         catch (Exception JavaDoc e)
138         {
139             pstmt = null;
140         }
141         addLog (0, null, new BigDecimal(counter), "@C_PeriodControl_ID@ @Created@");
142     } // createPeriodControls
143

144 } // DocumentTypeVerify
145
Popular Tags