KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_background > PeriodicAcctServer


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

17 package org.openbravo.erpCommon.ad_background;
18 import java.util.*;
19 import javax.servlet.*;
20 import java.io.*;
21 import org.openbravo.erpCommon.ad_forms.AcctServer;
22 import org.openbravo.base.secureApp.VariablesSecureApp;
23
24
25 public class PeriodicAcctServer implements BackgroundProcess {
26   public String JavaDoc batchSize="50";
27 // private final String[] TableIds = {"318","407","392","800019","319", "321", "323", "259", "224"};
28
private String JavaDoc[] TableIds = null;
29
30   public void processPL(PeriodicBackground periodicBG, boolean directProcess) throws Exception JavaDoc {
31     String JavaDoc adNoteId = "";
32     periodicBG.addLog("Iniciando proceso contable background.");
33     if (periodicBG.vars==null || periodicBG.adClientId.equals("")) {
34       try {
35         PeriodicAcctServerData[] dataOrg = PeriodicAcctServerData.selectUserOrg(periodicBG.conn, periodicBG.adProcessId);
36         if (dataOrg==null || dataOrg.length==0) {
37           periodicBG.addLog("La carga de organizaciĆ³n y usuario a fallado.");
38           periodicBG.setProcessing(false);
39           return;
40         }
41         periodicBG.vars = new VariablesSecureApp(dataOrg[0].adUserId, periodicBG.adClientId,dataOrg[0].adOrgId);
42       } catch (ServletException ex) {
43         ex.printStackTrace();
44         return;
45       }
46     }
47
48     try {
49         PeriodicAcctServerData [] data = PeriodicAcctServerData.selectAcctTable(periodicBG.conn);
50         ArrayList<Object JavaDoc> vTableIds = new ArrayList<Object JavaDoc>();
51         for (int i=0;i<data.length;i++){
52          vTableIds.add(data[i].adTableId);
53         }
54         TableIds = new String JavaDoc [vTableIds.size()];
55         vTableIds.toArray(TableIds);
56     } catch (ServletException ex) {
57       ex.printStackTrace();
58       return;
59     }
60     adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId);
61     String JavaDoc[] tables=null;
62     String JavaDoc strTable = "";
63     if (directProcess) {
64       strTable = PeriodicAcctServerData.selectTable(periodicBG.conn, periodicBG.adPinstanceId);
65     }
66     if (!strTable.equals("")) {
67       tables = new String JavaDoc[1];
68       tables[0] = new String JavaDoc(strTable);
69     } else tables = TableIds;
70     for (int i=0;i<tables.length;i++){
71       periodicBG.doPause();
72       AcctServer acct = AcctServer.get(tables[i], periodicBG.adClientId);
73       acct.setBatchSize(batchSize);
74       int total = 0;
75       while (acct.checkDocuments()) {
76         periodicBG.doPause();
77         if (total==0) periodicBG.addLog("Contabilizando - " + acct.tableName, false);
78         else periodicBG.addLog("Contabilizados " + total + " - " + acct.tableName, false);
79         try {
80           acct.run(periodicBG.vars);
81           periodicBG.doPause();
82         } catch(IOException ex) {
83           ex.printStackTrace();
84           return;
85         } catch(InterruptedException JavaDoc e) {
86           return;
87         }
88         if (!periodicBG.canContinue(directProcess, periodicBG.adClientId)) {
89           periodicBG.addLog("Table=" + acct.tableName + " - " +acct.getInfo(periodicBG.vars));
90           adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId);
91           return;
92         }
93         total += Integer.valueOf(batchSize).intValue();
94       }
95       periodicBG.addLog("Table=" + acct.tableName + " - " + acct.getInfo(periodicBG.vars));
96       adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId);
97     }
98   }
99 }
100
Popular Tags