Search in sources :

Example 11 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class AcctSchemaCopyAcct method copyDefault.

//	copyGL
/**
	 * 	Copy Default
	 *	@param targetAS target
	 *	@throws Exception
	 */
private void copyDefault(MAcctSchema targetAS) throws Exception {
    MAcctSchemaDefault source = MAcctSchemaDefault.get(getCtx(), p_SourceAcctSchema_ID);
    MAcctSchemaDefault target = new MAcctSchemaDefault(getCtx(), 0, get_TrxName());
    target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
    target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
    ArrayList<KeyNamePair> list = source.getAcctInfo();
    for (int i = 0; i < list.size(); i++) {
        KeyNamePair pp = list.get(i);
        int sourceC_ValidCombination_ID = pp.getKey();
        String columnName = pp.getName();
        MAccount sourceAccount = MAccount.get(getCtx(), sourceC_ValidCombination_ID);
        MAccount targetAccount = createAccount(targetAS, sourceAccount);
        target.setValue(columnName, new Integer(targetAccount.getC_ValidCombination_ID()));
    }
    if (!target.save())
        throw new AdempiereSystemError("Could not Save Default");
}
Also used : AdempiereSystemError(org.compiere.util.AdempiereSystemError) MAcctSchemaDefault(org.compiere.model.MAcctSchemaDefault) MAccount(org.compiere.model.MAccount) KeyNamePair(org.compiere.util.KeyNamePair)

Example 12 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class FindWindow method getSubCategoryWhereClause.

//  isProductCategoryField
/**
     * Returns a sql where string with the given category id and all of its subcategory ids.
     * It is used as restriction in MQuery.
     * @param productCategoryId
     * @return
    **/
private String getSubCategoryWhereClause(int productCategoryId) {
    //if a node with this id is found later in the search we have a loop in the tree
    int subTreeRootParentId = 0;
    String retString = " M_Product_Category_ID IN (";
    String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
    final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
    try {
        Statement stmt = DB.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            if (rs.getInt(1) == productCategoryId) {
                subTreeRootParentId = rs.getInt(2);
            }
            categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
        }
        retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId);
        retString += ") ";
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
        retString = "";
    } catch (AdempiereSystemError e) {
        log.log(Level.SEVERE, sql, e);
        retString = "";
    }
    return retString;
}
Also used : SQLException(java.sql.SQLException) AdempiereSystemError(org.compiere.util.AdempiereSystemError) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Vector(java.util.Vector)

Example 13 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class MSLACriteria method newInstance.

//	getGoals
/**
	 * 	Create New Instance of SLA Criteria
	 *	@return instanciated class
	 *	@throws Exception
	 */
public SLACriteria newInstance() throws Exception {
    if (getClassname() == null || getClassname().length() == 0)
        throw new AdempiereSystemError("No SLA Criteria Classname");
    try {
        Class clazz = Class.forName(getClassname());
        SLACriteria retValue = (SLACriteria) clazz.newInstance();
        return retValue;
    } catch (Exception e) {
        throw new AdempiereSystemError("Could not intsnciate SLA Criteria", e);
    }
}
Also used : SLACriteria(org.compiere.sla.SLACriteria) AdempiereSystemError(org.compiere.util.AdempiereSystemError)

Example 14 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class IssueReport method doIt.

//	prepare
/**
	 * 	Do It
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("AD_Issue_ID=" + m_AD_Issue_ID);
    if (!MSystem.get(getCtx()).isAutoErrorReport())
        return "NOT reported - Enable Error Reporting in Window System";
    //
    MIssue issue = new MIssue(getCtx(), m_AD_Issue_ID, get_TrxName());
    if (issue.get_ID() == 0)
        return "No Issue to report - ID=" + m_AD_Issue_ID;
    //
    String error = issue.report();
    if (error != null)
        throw new AdempiereSystemError(error);
    if (issue.save())
        return "Issue Reported: " + issue.getRequestDocumentNo();
    throw new AdempiereSystemError("Issue Not Saved");
}
Also used : MIssue(org.compiere.model.MIssue) AdempiereSystemError(org.compiere.util.AdempiereSystemError)

Example 15 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class InventoryCountCreate method getSubCategoriesString.

/**
	 * Recursive search for subcategories with loop detection.
	 * @param productCategoryId
	 * @param categories
	 * @param loopIndicatorId
	 * @return comma seperated list of category ids
	 * @throws AdempiereSystemError if a loop is detected
	 */
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
    String ret = "";
    final Iterator iter = categories.iterator();
    while (iter.hasNext()) {
        SimpleTreeNode node = (SimpleTreeNode) iter.next();
        if (node.getParentId() == productCategoryId) {
            if (node.getNodeId() == loopIndicatorId) {
                throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId);
            }
            ret = ret + getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId) + ",";
        }
    }
    log.fine(ret);
    return ret + productCategoryId;
}
Also used : AdempiereSystemError(org.compiere.util.AdempiereSystemError) Iterator(java.util.Iterator)

Aggregations

AdempiereSystemError (org.compiere.util.AdempiereSystemError)36 ResultSet (java.sql.ResultSet)9 BigDecimal (java.math.BigDecimal)8 PreparedStatement (java.sql.PreparedStatement)8 AdempiereUserError (org.compiere.util.AdempiereUserError)8 Timestamp (java.sql.Timestamp)6 MAcctSchema (org.compiere.model.MAcctSchema)5 MPayment (org.compiere.model.MPayment)5 MInvoice (org.compiere.model.MInvoice)4 SQLException (java.sql.SQLException)3 MInventory (org.compiere.model.MInventory)3 MTable (org.compiere.model.MTable)3 Statement (java.sql.Statement)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Vector (java.util.Vector)2 MAccount (org.compiere.model.MAccount)2 MAcctSchemaDefault (org.compiere.model.MAcctSchemaDefault)2 MColumn (org.compiere.model.MColumn)2 MDocType (org.compiere.model.MDocType)2 MWarehouse (org.compiere.model.MWarehouse)2