MBOMProduct.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.compiere.model |
![]() |
![]() |
Compiere |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/******************************************************************************
* Product: Compiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* This program is free software, you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY, without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program, if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 3600 Bridge Parkway #102, Redwood City, CA 94065, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* BOM Product/Component Model
*
* @author Jorg Janke
* @version $Id: MBOMProduct.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
*/
public class MBOMProduct extends X_M_BOMProduct
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Get Products of BOM
* @param bom bom
* @return array of BOM Products
*/
public static MBOMProduct[] getOfBOM (MBOM bom)
{
ArrayList<MBOMProduct> list = new ArrayList<MBOMProduct>();
String sql = "SELECT * FROM M_BOMProduct WHERE M_BOM_ID=? AND IsActive = 'Y' ORDER BY Line";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, bom.get_TrxName());
pstmt.setInt (1, bom.getM_BOM_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MBOMProduct (bom.getCtx(), rs, bom.get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MBOMProduct[] retValue = new MBOMProduct[list.size ()];
list.toArray (retValue);
return retValue;
} // getOfProduct
/**
* Get BOM Lines for Product. Default to Current Active, Master BOM
* @param product product
* @return array of BOMs
*/
public static MBOMProduct[] getBOMLines (MProduct product)
{
// return lines for Current Active, Master BOM
return getBOMLines(product, MBOM.BOMTYPE_CurrentActive, MBOM.BOMUSE_Master);
} // getBOMLines
/**
* Get BOM Lines for Product. Default to Current Active, Master BOM
* @param product product
* @param bomType bomtype
* @param bomUse bomuse
* @return array of BOMs
*/
public static MBOMProduct[] getBOMLines (MProduct product, String bomType, String bomUse)
{
// return lines for Current Active, Master BOM
String sql = "SELECT M_BOM_ID FROM M_BOM WHERE M_Product_ID=? " +
"AND BOMType = ? AND BOMUse = ? AND IsActive = 'Y' ";
String trxName = product.get_TrxName();
int bomID = 0;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, product.getM_Product_ID());
pstmt.setString(2, bomType);
pstmt.setString(3, bomUse);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
bomID = rs.getInt(1);
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
return getBOMLines(MBOM.get(product.getCtx(), bomID));
} // getBOMLines
/**
* Get BOM Lines for Product given a specific BOM
* @param ctx context
* @param M_Product_ID product
* @param trxName transaction
* @return array of BOMs
*/
public static MBOMProduct[] getBOMLines (MBOM bom)
{
String sql = "SELECT * FROM M_BOMProduct WHERE M_BOM_ID=? AND IsActive='Y' ORDER BY Line";
ArrayList<MBOMProduct> list = new ArrayList<MBOMProduct>();
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, bom.get_TrxName());
pstmt.setInt(1, bom.getM_BOM_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MBOMProduct (bom.getCtx(), rs, bom.get_TrxName()));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
//
MBOMProduct[] retValue = new MBOMProduct[list.size()];
list.toArray(retValue);
return retValue;
} // getBOMLines
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MBOMProduct.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_BOMProduct_ID id
* @param trxName trx
*/
public MBOMProduct (Ctx ctx, int M_BOMProduct_ID, String trxName)
{
super (ctx, M_BOMProduct_ID, trxName);
if (M_BOMProduct_ID == 0)
{
// setM_BOM_ID (0);
setBOMProductType (BOMPRODUCTTYPE_StandardProduct); // S
setBOMQty (Env.ONE);
setIsPhantom (false);
setLeadTimeOffset (0);
// setLine (0); // @SQL=SELECT NVL(MAX(Line),0)+10 AS DefaultValue FROM M_BOMProduct WHERE M_BOM_ID=@M_BOM_ID@
}
} // MBOMProduct
/**
* Parent Constructor
* @param bom product
*/
public MBOMProduct (MBOM bom)
{
this (bom.getCtx(), 0, bom.get_TrxName());
m_bom = bom;
m_component = null;
m_componentBOM = null;
} // MBOMProduct
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MBOMProduct (Ctx ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MBOMProduct
/** BOM Parent */
private MBOM m_bom = null;
/**
* Get Parent
* @return parent
*/
public MBOM getBOM()
{
if (m_bom == null && getM_BOM_ID() != 0)
m_bom = MBOM.get(getCtx(), getM_BOM_ID());
return m_bom;
} // getBOM
/** Included Component */
private MProduct m_component = null;
/**
* Get included component
* @return product
*/
public MProduct getComponent()
{
if (m_component == null && getM_ProductBOM_ID() != 0)
m_component = MProduct.get (getCtx(), getM_ProductBOM_ID());
return m_component;
} // getComponent
/**
* Set component
* @param M_ProductBOM_ID product ID
*/
@Override
public void setM_ProductBOM_ID(int M_ProductBOM_ID)
{
super.setM_ProductBOM_ID (M_ProductBOM_ID);
m_component = null;
} // setM_ProductBOM_ID
/** Component BOM */
private MBOM m_componentBOM = null;
/**
* Get Component BOM
* @return MBOM
*/
public MBOM getComponentBOM()
{
if (m_componentBOM == null && getM_ProductBOMVersion_ID() != 0)
m_componentBOM = MBOM.get(getCtx(), getM_ProductBOMVersion_ID());
return m_componentBOM;
} // getComponentBOM
/**
* Set component BOM
* @param M_ProductBOM_ID product ID
*/
@Override
public void setM_ProductBOMVersion_ID(int M_ProductBOMVersion_ID)
{
super.setM_ProductBOMVersion_ID (M_ProductBOMVersion_ID);
m_componentBOM = null;
} // setM_ProductBOMVersion_ID
/** Info
@return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("MBOMProduct[").append(get_ID()).append(",ComponentProduct=").
append(getComponent().getName()).append("]");
return sb.toString();
}
/**
* Before Save
* @param newRecord new
* @return true/false
*/
@Override
protected boolean beforeSave (boolean newRecord)
{
// Product
if (getBOMProductType().equals(BOMPRODUCTTYPE_OutsideProcessing))
{
if (getM_ProductBOM_ID() != 0)
setM_ProductBOM_ID(0);
}
else if (getM_ProductBOM_ID() == 0)
{
log.saveError("Error", Msg.parseTranslation(getCtx(), "@NotFound@ @M_ProductBOM_ID@"));
return false;
}
// Product Attribute Instance
if (getM_AttributeSetInstance_ID() != 0)
{
getBOM();
if (m_bom != null
&& X_M_BOM.BOMTYPE_Make_To_Order.equals(m_bom.getBOMType()))
;
else
{
log.saveError("Error", Msg.parseTranslation(getCtx(),
"Reset @M_AttributeSetInstance_ID@: Not Make-to-Order"));
setM_AttributeSetInstance_ID(0);
return false;
}
}
// Alternate
if ((getBOMProductType().equals(BOMPRODUCTTYPE_Alternative)
|| getBOMProductType().equals(BOMPRODUCTTYPE_AlternativeDefault)))
{
if (getM_BOMAlternative_ID() == 0)
{
log.saveError("Error", Msg.parseTranslation(getCtx(), "@NotFound@ @M_BOMAlternative_ID@"));
return false;
}
}
else
{
setM_BOMAlternative_ID(0);
}
// Operation
if (getM_ProductOperation_ID() != 0)
{
if (getSeqNo() == 0)
{
log.saveError("Error", Msg.parseTranslation(getCtx(), "@NotFound@ @SeqNo@"));
return false;
}
}
else // no op
{
if (getSeqNo() != 0)
setSeqNo(0);
if (getLeadTimeOffset() != 0)
setLeadTimeOffset(0);
}
// Set Line Number
if (getLine() == 0)
{
String sql = "SELECT NVL(MAX(Line),0)+10 FROM M_BOMProduct WHERE M_BOM_ID=?";
int ii = DB.getSQLValue (get_TrxName(), sql, getM_BOM_ID());
setLine (ii);
}
return true;
} // beforeSave
/**
* After Save
* @param newRecord new
* @param success success
* @return success
*/
@Override
protected boolean afterSave (boolean newRecord, boolean success)
{
// BOM Component Line was changed
if (newRecord || is_ValueChanged("M_ProductBOM_ID") || is_ValueChanged("M_ProductBOMVersion_ID") || is_ValueChanged("IsActive"))
{
MBOM mbom = new MBOM (getCtx(), getM_BOM_ID(), get_TrxName());
// Invalidate BOM
MProduct product = new MProduct (getCtx(), mbom.getM_Product_ID(), get_TrxName());
if (get_TrxName() != null)
product.load(get_TrxName());
if (product.isVerified())
{
product.setIsVerified(false);
product.save(get_TrxName());
}
// Invalidate Products where BOM is used
}
return success;
} // afterSave
} // MBOMProduct
The table below shows all metrics for MBOMProduct.java.




