KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > report > MReportSource


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.report;
15
16 import java.util.*;
17 import java.sql.*;
18 import java.math.*;
19 import java.io.Serializable JavaDoc;
20
21 import org.compiere.model.*;
22 import org.compiere.util.*;
23
24
25 /**
26  * Report Line Source Model
27  *
28  * @author Jorg Janke
29  * @version $Id: MReportSource.java,v 1.12 2003/11/02 07:49:20 jjanke Exp $
30  */

31 public class MReportSource extends X_PA_ReportSource
32 {
33     /**
34      * Constructor
35      * @param ctx context
36      * @param PA_ReportSource_ID id
37      */

38     public MReportSource (Properties ctx, int PA_ReportSource_ID)
39     {
40         super (ctx, PA_ReportSource_ID);
41         if (PA_ReportSource_ID == 0)
42         {
43         }
44     } // MReportSource
45

46     /**
47      * Constructor
48      * @param ctx context
49      * @param rs ResultSet to load from
50      */

51     public MReportSource (Properties ctx, ResultSet rs)
52     {
53         super (ctx, rs);
54     } // MReportSource
55

56
57     /** Map with Tree */
58     private static CCache s_trees = new CCache("reportSourceTrees", 20);
59
60     /**
61      * Get SQL where clause
62      * @return where clause
63      */

64     public String JavaDoc getWhereClause()
65     {
66         String JavaDoc et = getElementType();
67         String JavaDoc TreeType = et;
68
69         // Get Key ColumnName & ID for tree
70
String JavaDoc ColumnName = AcctSchemaElement.getColumnName(et);
71         int ID = 0;
72         //
73
if (AcctSchemaElement.SEGMENT_Account.equals(et))
74         {
75             ID = getC_ElementValue_ID ();
76             TreeType = X_AD_Tree.TREETYPE_ElementValueAccountEtc;
77         }
78         else if (AcctSchemaElement.SEGMENT_Activity.equals(et))
79             ID = getC_Activity_ID ();
80         else if (AcctSchemaElement.SEGMENT_BPartner.equals(et))
81             ID = getC_BPartner_ID ();
82         else if (AcctSchemaElement.SEGMENT_Campaign.equals(et))
83             ID = getC_Campaign_ID ();
84         else if (AcctSchemaElement.SEGMENT_LocationFrom.equals(et))
85             ID = getC_Location_ID ();
86         else if (AcctSchemaElement.SEGMENT_LocationTo.equals(et))
87             ID = getC_Location_ID ();
88         else if (AcctSchemaElement.SEGMENT_Org.equals(et))
89             ID = getOrg_ID ();
90         else if (AcctSchemaElement.SEGMENT_Product.equals(et))
91             ID = getM_Product_ID ();
92         else if (AcctSchemaElement.SEGMENT_Project.equals(et))
93             ID = getC_Project_ID ();
94         else if (AcctSchemaElement.SEGMENT_SalesRegion.equals(et))
95             ID = getC_SalesRegion_ID ();
96         else if (AcctSchemaElement.SEGMENT_OrgTrx.equals(et))
97             ID = getOrg_ID (); // (re)uses Org_ID
98
else if (AcctSchemaElement.SEGMENT_User1.equals(et))
99             ID = getC_ElementValue_ID ();
100         else if (AcctSchemaElement.SEGMENT_User2.equals(et))
101             ID = getC_ElementValue_ID ();
102
103         // Get Tree
104
MTree tree = (MTree)s_trees.get(et);
105         if (tree == null)
106         {
107             tree = MTree.getTree (getCtx(), TreeType);
108             Log.trace(Log.l4_Data, "MReportSource.getWhereClause - create tree for " + TreeType, tree);
109             s_trees.put(et, tree);
110         }
111         // Search in Tree
112
if (tree != null)
113         {
114             MTreeNode node = tree.getRoot().findNode(ID);
115             /** @todo remove Print Tree debug */
116             System.out.println("Root=" + node);
117             if (node != null && node.isSummary())
118             {
119                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
120                 Enumeration en = node.preorderEnumeration();
121                 while (en.hasMoreElements())
122                 {
123                     MTreeNode nn = (MTreeNode)en.nextElement();
124                     if (!nn.isSummary())
125                     {
126                         if (sb.length () > 0)
127                             sb.append (",");
128                         sb.append(nn.getID());
129                         // temp debug
130
System.out.println(" - " + nn);
131                     }
132                     else
133                         System.out.println(" - skipped parent (" + nn + ")");
134                 }
135                 return new StringBuffer JavaDoc (ColumnName).append(" IN (").append(sb).append(")").toString();
136             }
137         }
138
139         // Nothing found or not summary
140
return new StringBuffer JavaDoc (ColumnName).append("=").append(ID).toString();
141     } // getWhereClause
142

143
144     /**
145      * String Representation
146      * @return info
147      */

148     public String JavaDoc toString ()
149     {
150         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MReportSource[")
151             .append(getID()).append(" - ").append(getDescription())
152             .append(" - ").append(getElementType())
153             .append(" - ").append(getWhereClause());
154         sb.append ("]");
155         return sb.toString ();
156     } // toString
157

158     /**
159      * Set Parent.
160      * @param PA_ReportLine_ID parent
161      */

162     private void setPA_ReportLine_ID (int PA_ReportLine_ID)
163     {
164         setValueNoCheck ("PA_ReportLine_ID", new Integer JavaDoc(PA_ReportLine_ID));
165     } // setPA_ReportLine_ID
166

167
168     /*************************************************************************/
169
170     /**
171      * Copy Constructor
172      * @param ctx context
173      * @param AD_Client_ID parent
174      * @param AD_Org_ID parent
175      * @param PA_ReportLine_ID parent
176      * @param source copy source
177      * @return Report Source
178      */

179     public static MReportSource copy (Properties ctx, int AD_Client_ID, int AD_Org_ID, int PA_ReportLine_ID, MReportSource source)
180     {
181         MReportSource retValue = new MReportSource (ctx, 0);
182         MReportSource.copyValues(source, retValue, AD_Client_ID, AD_Org_ID);
183         retValue.setPA_ReportLine_ID(PA_ReportLine_ID);
184         return retValue;
185     } // copy
186

187 } // MReportSource
188
Popular Tags