Search in sources :

Example 1 with X_AD_Val_Rule

use of org.compiere.model.X_AD_Val_Rule in project adempiere by adempiere.

the class DynValRuleElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int AD_Val_Rule_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID);
    if (rules.contains(AD_Val_Rule_ID))
        return;
    rules.add(AD_Val_Rule_ID);
    String sql = "SELECT Name FROM AD_Val_Rule WHERE  AD_Val_Rule_ID= " + AD_Val_Rule_ID;
    AttributesImpl atts = new AttributesImpl();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        rs = pstmt.executeQuery();
        while (rs.next()) {
            X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule(ctx, AD_Val_Rule_ID, null);
            createDynamicValidationRuleBinding(atts, m_ValRule);
            document.startElement("", "", "dynvalrule", atts);
            document.endElement("", "", "dynvalrule");
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "getProcess", e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
}
Also used : X_AD_Val_Rule(org.compiere.model.X_AD_Val_Rule) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SAXException(org.xml.sax.SAXException)

Example 2 with X_AD_Val_Rule

use of org.compiere.model.X_AD_Val_Rule in project adempiere by adempiere.

the class RecordInfoController method dynInit.

/**
	 * 	Dynamic Init
	 *	@param dse data status event
	 *	@param title title
	 *	@param mField field
	 */
private void dynInit(DataStatusEvent dse, String title, GridField mField) {
    m_Field = mField;
    //	Yamel Senih FR[ 146 ] Add support to change log in a specific column
    //	2015-12-03
    //	For Field
    int m_Record_ID = 0;
    int m_AD_Table_ID = 0;
    int m_AD_Column_ID = 0;
    if (m_Field != null) {
        //	Set Values
        m_Record_ID = m_Field.getGridTab().getRecord_ID();
        m_AD_Table_ID = m_Field.getGridTab().getAD_Table_ID();
        m_AD_Column_ID = m_Field.getAD_Column_ID();
        //	
        MColumn column = MColumn.get(Env.getCtx(), m_AD_Column_ID);
        X_AD_Reference reference = new X_AD_Reference(Env.getCtx(), m_Field.getDisplayType(), null);
        DecimalFormat format = DisplayType.getNumberFormat(reference.getAD_Reference_ID());
        MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
        //  Info
        m_info.append("(").append(table.getTableName()).append(" - ").append(m_Field.getColumnName()).append(" = ").append(m_Field.getValue()).append(")").append("\n").append(Msg.translate(Env.getCtx(), "Name")).append(": ").append(m_Field.getHeader()).append("\n").append(Msg.translate(Env.getCtx(), "Description")).append(": ").append(m_Field.getDescription()).append("\n").append(Msg.translate(Env.getCtx(), "AD_Reference_ID")).append(": ").append(reference.get_Translation("Name")).append("\n");
        //	For Reference Key
        if (m_Field.getDisplayType() == DisplayType.List || m_Field.getDisplayType() == DisplayType.Table || m_Field.getDisplayType() == DisplayType.Search) {
            //	Valid Reference Value
            if (m_Field.getAD_Reference_Value_ID() != 0) {
                X_AD_Reference referenceKey = new X_AD_Reference(Env.getCtx(), m_Field.getAD_Reference_Value_ID(), null);
                m_info.append(Msg.translate(Env.getCtx(), "AD_Reference_Value_ID")).append(": ").append(referenceKey.get_Translation("Name")).append(" (").append(m_Field.getAD_Reference_Value_ID()).append(")").append("\n");
            }
        }
        //	Valid Dynamic Validation
        if (column.getAD_Val_Rule_ID() != 0) {
            X_AD_Val_Rule validation = (X_AD_Val_Rule) column.getAD_Val_Rule();
            m_info.append(Msg.translate(Env.getCtx(), "AD_Val_Rule_ID")).append(": ").append(validation.get_Translation("Name")).append(" (").append(column.getAD_Val_Rule_ID()).append(")").append("\n");
        }
        m_info.append(Msg.translate(Env.getCtx(), "Length")).append(": ").append(format.format(column.getFieldLength())).append("\n");
        //	Add Entity Type for info
        MEntityType entity = MEntityType.get(Env.getCtx(), column.getEntityType());
        m_info.append(Msg.translate(Env.getCtx(), "EntityType")).append(": ").append(entity.get_Translation("Name"));
        //	Title
        m_Title = title + " - " + m_Field.getHeader();
    } else {
        if (dse.CreatedBy == null)
            return;
        //  Info
        MUser user = MUser.get(Env.getCtx(), dse.CreatedBy.intValue());
        m_info.append(" ").append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Created)).append("\n");
        if (!dse.Created.equals(dse.Updated) || !dse.CreatedBy.equals(dse.UpdatedBy)) {
            if (!dse.CreatedBy.equals(dse.UpdatedBy))
                user = MUser.get(Env.getCtx(), dse.UpdatedBy.intValue());
            m_info.append(" ").append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Updated)).append("\n");
        }
        if (dse.Info != null && dse.Info.length() > 0)
            m_info.append("\n (").append(dse.Info).append(")");
        //	Title
        if (dse.AD_Table_ID != 0) {
            m_AD_Table_ID = dse.AD_Table_ID;
            MTable table1 = MTable.get(Env.getCtx(), dse.AD_Table_ID);
            m_Title = title + " - " + table1.getName();
        }
        //	Set Record ID
        if (dse.Record_ID instanceof Integer)
            m_Record_ID = ((Integer) dse.Record_ID).intValue();
        else
            log.info("dynInit - Invalid Record_ID=" + dse.Record_ID);
    }
    //	Valid Record Identifier
    if (m_Record_ID == 0)
        return;
    //	Only Client Preference can view Change Log
    if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()))
        return;
    //	Data
    String sql = "SELECT AD_Column_ID, Updated, UpdatedBy, OldValue, NewValue " + "FROM AD_ChangeLog " + "WHERE AD_Table_ID=? AND Record_ID=? " + (m_AD_Column_ID != 0 ? "AND AD_Column_ID=? " : "") + "ORDER BY Updated DESC";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Table_ID);
        pstmt.setInt(2, m_Record_ID);
        //	Add support to column
        if (m_AD_Column_ID != 0)
            pstmt.setInt(3, m_AD_Column_ID);
        //	
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            addLine(rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    //	Set Loaded to Ok
    m_IsLoaded = true;
}
Also used : MColumn(org.compiere.model.MColumn) DecimalFormat(java.text.DecimalFormat) PreparedStatement(java.sql.PreparedStatement) X_AD_Val_Rule(org.compiere.model.X_AD_Val_Rule) X_AD_Reference(org.compiere.model.X_AD_Reference) MTable(org.compiere.model.MTable) ResultSet(java.sql.ResultSet) MEntityType(org.compiere.model.MEntityType) MUser(org.compiere.model.MUser)

Example 3 with X_AD_Val_Rule

use of org.compiere.model.X_AD_Val_Rule in project adempiere by adempiere.

the class DynValRuleElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        String name = atts.getValue("Name");
        int id = get_IDWithColumn(ctx, "AD_Val_Rule", "name", name);
        X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule(ctx, id, getTrxName(ctx));
        if (id <= 0 && atts.getValue("AD_Val_Rule_ID") != null && Integer.parseInt(atts.getValue("AD_Val_Rule_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_ValRule.setAD_Val_Rule_ID(Integer.parseInt(atts.getValue("AD_Val_Rule_ID")));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_Val_Rule", m_ValRule);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_ValRule.setDescription(getStringValue(atts, "Description"));
        m_ValRule.setEntityType(atts.getValue("EntityType"));
        m_ValRule.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_ValRule.setName(name);
        m_ValRule.setType(atts.getValue("Type"));
        m_ValRule.setCode(atts.getValue("Code"));
        if (m_ValRule.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_ValRule.getName(), "ValRule", m_ValRule.get_ID(), AD_Backup_ID, Object_Status, "AD_Val_Rule", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Val_Rule"));
        } else {
            record_log(ctx, 0, m_ValRule.getName(), "ValRule", m_ValRule.get_ID(), AD_Backup_ID, Object_Status, "AD_Val_Rule", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Val_Rule"));
            throw new POSaveFailedException("Failed to save dynamic validation rule.");
        }
    } else {
        element.skip = true;
    }
}
Also used : X_AD_Val_Rule(org.compiere.model.X_AD_Val_Rule) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Aggregations

X_AD_Val_Rule (org.compiere.model.X_AD_Val_Rule)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)2 DecimalFormat (java.text.DecimalFormat)1 MColumn (org.compiere.model.MColumn)1 MEntityType (org.compiere.model.MEntityType)1 MTable (org.compiere.model.MTable)1 MUser (org.compiere.model.MUser)1 X_AD_Reference (org.compiere.model.X_AD_Reference)1 Attributes (org.xml.sax.Attributes)1 SAXException (org.xml.sax.SAXException)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1