 |
red1.org Nihili est - in vita priore ego imperator romanus fui
|
| View previous topic :: View next topic |
| Author |
Message |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Fri Mar 31, 2006 9:23 pm Post subject: Developer's Education |
|
|
David is capable of understanding the java programming needed in velocity java. I shown some tricks on how it interacts with velocity UI edited via Dreamweaver.
We want to reverse engineer the present system as it is been used and once coded can be extended to cover scheduling and integration to Compiere. At the moment after going thru with Caterin and Joni, it seems to be a flat almost excel like. Thus we can easily used excel to represent every page in the legacy clipper app, with cell formulas.
I did one page to corelate alt2 with alt-P.
We can quickly setup the same in velocity and build into tables. Once formulas and relations are clear, we can knit to Compiere oracle tables.
I have packaged a basic medan framework that drill into Compiere oracle.
From there u can see a simple 3 tier coding with the common stmts that u need in further java classes.
For more elaborate tricks, u can refer to the Mecca2 project. |
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Sat Apr 01, 2006 12:23 pm Post subject: |
|
|
i have extended the Medan package to do DataUpdate. It is POC that Medan can write to Compiere, but we allow only update for application integrity issue.
Thus to update anything that is NOT in Compiere yet, we have to create it in Compiere first. I.e. new product. Then Medan can use that new record for further update i.e. from the Estimation module to the BOM table. |
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Wed May 03, 2006 10:28 am Post subject: |
|
|
Here is a good link given by Sam http://www.java2s.com/Code/Java/Velocity/CatalogVelocity.htm
Here i paste one example from it so that u are convinced: | Code: | import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
public class MapDemo {
public static void main(String[] args) throws Exception {
Velocity.init();
Template t = Velocity.getTemplate("./src/mapProperty.vm");
VelocityContext ctx = new VelocityContext();
Map map = new HashMap();
map.put("firstName", "Joe");
map.put("lastName", "Yin");
ctx.put("map", map);
Writer writer = new StringWriter();
t.merge(ctx, writer);
System.out.println(writer);
}
}
-------------------------------------------------------------------------------------
My first name is $map.firstName
My last name is $map.lastName |
|
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Wed May 03, 2006 11:36 am Post subject: |
|
|
Here is another example. Notice that java code does no business logic. The VM can manipulate | Code: | public class VMDemo {
public static void main(String[] args) throws Exception {
Velocity.init();
Template t = Velocity.getTemplate("./src/VMDemo.vm");
VelocityContext ctx = new VelocityContext();
Writer writer = new StringWriter();
t.merge(ctx, writer);
System.out.println(writer);
}
}
-------------------------------------------------------------------------------------
<html>
<head>
<title>Gimli's Widgetarium</title>
</head>
<body>
<table>
#set ($rowCount = 1)
#set ($products = ["one", "two", "three"])
#foreach($product in $products)
#if ($rowCount % 2 == 0)
#set ($bgcolor = "#FFFFFF")
#else
#set ($bgcolor = "#CCCCCC")
#end
<tr>
<td bgcolor="$bgcolor">$product</td>
<td bgcolor="$bgcolor">$product</td>
</tr>
#set ($rowCount = $rowCount + 1)
#end
</table>
</body>
</html> |
|
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Wed May 03, 2006 3:02 pm Post subject: |
|
|
Here i like to show a snapshot of how i start to code sumtin. Here is the generateJobs.java halfway, just warming up, so that David can appreciate it before it takes further shape. U can check it out later from CVS. | Code: | public class generateJobs {
//main method - doing tasks
// 1) reading from Production Table to get orders, its qtys and the products
// 2) make2Qty creates the JobResource records (may reuse the QFloor methods)
public static Vector doIt()throws Exception
{
String OrderID = "";
int qty = 0;
String prodId = "";
Vector v = readProduction();
for (int i=0; i < v.size(); i++){
Hashtable h = (Hashtable)v.elementAt(i);
OrderID = (String)h.get("OrderID");
qty = ((Integer)h.get("qty")).intValue();
prodId = (String)h.get("prodId");
make2Qty(OrderID, qty, prodId);
}
return null;
}
public static Vector readProduction() throws Exception
{
//read from ProductionPlan, make sure its 'Processed' = "N"
//put each ProdID values Qty and OrderID (Description) into Vector
//ignore those without OrderID
return null;
}
public static Vector make2Qty(String OrderID, int qty, String prodID) throws Exception
{
//based on Qty, create each JobResource record with unique SerialNos
return null;
}
} |
|
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Wed May 03, 2006 3:30 pm Post subject: |
|
|
and now it has taken more shape: | Code: | public class generateJobs {
//main method - doing tasks
// 1) reading from Production Table to get orders, its qtys and the products
// 2) make2Qty creates the JobResource records (may reuse the QFloor methods)
public static Vector doIt()throws Exception
{
String desc = "";
String OrderID = "";
int qty = 0;
String prodId = "";
Vector v = readProduction();
for (int i=0; i < v.size(); i++){
Hashtable h = (Hashtable)v.elementAt(i);
desc = (String)h.get("Description");
if (!desc.equals("")){
OrderID = (String)h.get("OrderID");
qty = ((Integer)h.get("qty")).intValue();
prodId = (String)h.get("prodId");
make2Qty(desc, OrderID, qty, prodId);
}
}
return null;
}
public static Vector make2Qty(String desc, String OrderID, int qty, String prodID) throws Exception
{
//based on Qty, create each JobResource record with unique SerialNos
if (notExisted(desc,"P_Job")){
}
return null;
}
// ========== minor methods ==================
private static boolean notExisted(String desc, String table) throws Exception{
Hashtable h = access(desc, table);
if (h.isEmpty())return true;
return false;
}
// ================= end of methods ========= start of doSQLs =========
public static Vector readProduction() throws Exception {
String[][] fields = {
{"P_WorkCentre_Key", "string"},
{"P_WorkCentre_Name", "string"},
{"P_WorkCentre_ID", "string"},
{"P_Sequence", "string"},
{"IsActive", "string"}
};
Vector list = new DataHelper()
{
public String doSQL() {
SQLRenderer r = new SQLRenderer();
r.add("M_Product_ID");
r.add("ProductionQty");
r.add("Processed");
r.add("Description");
r.add("IsActive","Y");
return r.getSQLSelect("M_ProductionPlan");
}
}.getHashtableList(fields);
return list;
}
public static Hashtable access(final String value, final String c_Table) throws Exception{
String[][] fields = {
{"P_Job_SerialNo", "string"},
};
Hashtable list = new DataHelper()
{
public String doSQL() {
SQLRenderer r = new SQLRenderer();
r.add("P_Job_SerialNo");
r.add("P_Job_SerialNo", value);
return r.getSQLSelect(c_Table);
}
}.getHashtable(fields);
return list;
}
} |
|
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Wed May 03, 2006 4:55 pm Post subject: |
|
|
finally.... but not tested ... once tested i will CVS and post to the POC thread. | Code: | package shopfloor.queue;
import java.util.Hashtable;
import java.util.Vector;
import shopfloor.tools.BOMFlatView;
import mecca.db.DataHelper;
import mecca.db.SQLRenderer;
import mecca.db.UniqueID;
/**
* @author red1
* @version 0.1 $Id$
*/
public class generateJobs {
//main method - doing tasks
// 1) reading from Production Table to get orders, its qtys and the products
// 2) make2Qty creates the JobResource records (may RE-USE external class methods)
public static Vector doIt()throws Exception
{
String desc = ""; //Order_ID
int qty = 0;
String prodId = "";
Vector v = readProduction();
for (int i=0; i < v.size(); i++){
Hashtable h = (Hashtable)v.elementAt(i);
desc = (String)h.get("Description");
if (!desc.equals("")){
qty = ((Integer)h.get("ProductionQty")).intValue();
prodId = (String)h.get("M_Product_ID");
Vector workctrs = fetch1stChilds(prodId);
make2Qty(desc, qty, prodId, workctrs);
}
}
return null;
}
// ========== minor methods ==================
//a tricky method - to loop QTY (taking serialNos), within loop WORKCTRS
public static Vector make2Qty(String OrderID, int qty, String prodID, Vector workctrs) throws Exception
{
//based on Qty, create each JobResource record with unique SerialNos
InputJobResource jobResource = new InputJobResource();
for ( int jobs=0;jobs<qty;jobs++){
String serialNo = UniqueID.getUID(); //later use preformated serialno
if (notExisted(OrderID,"P_Job")){
for (int i=0; i<workctrs.size(); i++){
Hashtable h = (Hashtable)workctrs.elementAt(i);
String workctr = (String)h.get("ProductValue"); //P_WorkCentre_Key
//RE-USE external class method to create new JobResource record
jobResource.newrec(OrderID,workctr, serialNo, "", "", "P_JobResource");
}
}
}
return null;
}
private static Vector fetch1stChilds(String ProdID) throws Exception{
// access ProductBOM first level childs
Vector v = BOMFlatView.listRaw(ProdID);
//get corresponding BOMResourceKey or WorkCentre (M_ProductionBOM_ID)
for (int i=0;i < v.size(); i++){
Hashtable h = (Hashtable)v.elementAt(i);
//RE-USE external class method BOMFlatView.getM_Product to convert ID to Name
Hashtable M_Product = BOMFlatView.getM_Product((String)h.get("M_ProductBOM_ID"));
h.put("ProductValue",M_Product.get("Value"));
}
return v;
}
private static boolean notExisted(String desc, String table) throws Exception{
Hashtable h = access(desc, table);
if (h.isEmpty())return true;
return false;
}
// ================= end of business methods ========= start of DB doSQLs =========
public static Vector readProduction() throws Exception {
String[][] fields = {
{"M_Product_ID", "string"},
{"Description", "string"},
{"ProductionQty", "string"}
};
Vector list = new DataHelper()
{
public String doSQL() {
SQLRenderer r = new SQLRenderer();
r.add("M_Product_ID");
r.add("ProductionQty");
r.add("Processed", "N");
r.add("Description");
r.add("IsActive","Y");
return r.getSQLSelect("M_ProductionPlan");
}
}.getHashtableList(fields);
return list;
}
public static Hashtable access(final String value, final String c_Table) throws Exception{
String[][] fields = {
{"P_Job_SerialNo", "string"}
};
Hashtable list = new DataHelper()
{
public String doSQL() {
SQLRenderer r = new SQLRenderer();
r.add("P_Job_SerialNo");
r.add("P_Job_SerialNo", value);
return r.getSQLSelect(c_Table);
}
}.getHashtable(fields);
return list;
}
} |
|
|
| Back to top |
|
 |
red1 Site Admin
Joined: 06 Jul 2004 Posts: 1756 Location: Kuala Lumpur, Malaysia
|
Posted: Thu May 04, 2006 6:33 am Post subject: |
|
|
Now the UI part. This GenerateJobs routine will be called from the QFloor.vm, so we go there and put a button. | Code: | | <input name="button" type="button" onClick="generateJobs()" value="Generate Jobs"> | And at the bottom of the QFloor.vm we add the function | Code: | <script>
function generateJobs() {
document.f.command.value = "generateJobs";
document.f.submit();
}
</script> | This shall pass 'generateJobs' as the value in submit parameter to the calling java - QFloor. Now in the QFloor.java we must accept this value, so we add the following: | Code: | | if (submit.equals("generateJobs")) generateJobs.doIt(); |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|