Search in sources :

Example 1 with MMessage

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

the class DeveloperModeBL method createMessageOrElement0.

private boolean createMessageOrElement0(Properties ctx, final String adLanguage, final String text, boolean checkMessage, boolean checkElement) {
    final String trxName = null;
    final MMessage message = checkMessage ? MMessage.get(ctx, text) : null;
    if (message != null) {
        return checkInsertTrl(message, adLanguage);
    }
    final M_Element element = checkElement ? M_Element.get(ctx, text) : null;
    if (element != null) {
        return checkInsertTrl(element, adLanguage);
    }
    boolean createMessage = checkMessage && isValidMessageValue(text);
    boolean createElement = checkElement && isValidColumnName(text);
    if (!createElement && !createMessage) {
        return false;
    }
    if (createElement && createMessage) {
        // TODO: ask developer what to do
        createMessage = true;
        createElement = false;
    }
    if (createMessage) {
        final MMessage messageNew = new MMessage(ctx, 0, trxName);
        messageNew.setValue(text);
        messageNew.setMsgType(X_AD_Message.MSGTYPE_Information);
        messageNew.setMsgText(text);
        messageNew.setEntityType(getEntityType(ctx));
        // The save will trigger CCache reset for "AD_Message" which will clear message from Msg class
        messageNew.saveEx();
        logger.log(Level.WARNING, "Created: " + messageNew + ", Value=" + messageNew.getValue() + ", EntityType=" + messageNew.getEntityType(), new Exception());
    }
    if (createElement) {
        final M_Element elementNew = new M_Element(ctx, 0, trxName);
        elementNew.setColumnName(text);
        elementNew.setName(text);
        elementNew.setPrintName(text);
        elementNew.setEntityType(getEntityType(ctx));
        elementNew.saveEx();
        logger.log(Level.WARNING, "Created: " + element + ", ColumnName=" + elementNew.getColumnName() + ", EntityType=" + elementNew.getEntityType(), new Exception());
    }
    return createMessage || createElement;
}
Also used : MMessage(org.compiere.model.MMessage) M_Element(org.compiere.model.M_Element)

Example 2 with MMessage

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

the class MRP method createMRPNote.

/**
	 * Create MRP Notice
	 * @param code MRP/DRP Code (see MRP-xxx and DRP-xxx messages)
	 * @param AD_Org_ID organization
	 * @param PP_MRP_ID MRP record id 
	 * @param product product (optional)
	 * @param documentNo Document# (optional)
	 * @param qty quantity (optional)
	 * @param comment comment (optional)
	 * @throws SQLException 
	 */
protected void createMRPNote(String code, int AD_Org_ID, int PP_MRP_ID, MProduct product, String documentNo, BigDecimal qty, String comment, String trxName) throws SQLException {
    int M_Warehouse_ID = MPPMRP.getM_Warehouse_ID(PP_MRP_ID, trxName);
    documentNo = documentNo != null ? documentNo : "";
    comment = comment != null ? comment : "";
    qty = qty != null ? qty : Env.ZERO;
    MMessage msg = MMessage.get(getCtx(), code);
    // If MRP code not found, use MRP-999 - unknown error 
    if (msg == null) {
        msg = MMessage.get(getCtx(), "MRP-999");
    }
    String message = msg.getValue() + " " + Msg.getMsg(getCtx(), msg.getValue());
    int user_id = 0;
    if (m_product_planning != null) {
        user_id = m_product_planning.getPlanner_ID();
    }
    if (M_Warehouse_ID > 0) {
        String warehouseName = DB.getSQLValueString(trxName, "SELECT Name FROM M_Warehouse  WHERE M_Warehouse_ID=? ", MPPMRP.getM_Warehouse_ID(PP_MRP_ID, trxName));
        message += "\n" + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_M_Warehouse_ID) + " : " + warehouseName;
    }
    if (product != null) {
        message += "\n" + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_M_Product_ID) + " : " + product.getValue() + " " + product.getName();
    }
    if (!Util.isEmpty(documentNo, true)) {
        message += "\n" + Msg.getElement(getCtx(), MPPOrder.COLUMNNAME_DocumentNo) + " : " + documentNo;
    }
    if (qty != null) {
        message += "\n" + Msg.translate(getCtx(), "QtyPlan") + " : " + qty;
    }
    if (!Util.isEmpty(comment, true)) {
        message += "\n" + comment;
    }
    String reference = "";
    if (PP_MRP_ID > 0) {
        reference = "M_Warehouse_ID" + "->" + M_Warehouse_ID + " | ";
    }
    reference = (reference != "" ? reference : reference) + "M_Product_ID" + "->" + product.get_ID();
    MNote note = new MNote(getCtx(), msg.getAD_Message_ID(), user_id, MPPMRP.Table_ID, PP_MRP_ID, reference, message, trxName);
    note.setAD_Org_ID(AD_Org_ID);
    note.saveEx();
    String noteMessage = documentNo != null && documentNo.length() > 0 ? "@DocumentNo@ : " + documentNo + " -> " + message : message;
    addLog(noteMessage);
    log.info(code + ": " + note.getTextMsg());
    count_Msg += 1;
}
Also used : MMessage(org.compiere.model.MMessage) MNote(org.compiere.model.MNote)

Example 3 with MMessage

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

the class MessageElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Value"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        String value = atts.getValue("Value");
        int id = get_IDWithColumn(ctx, "AD_Message", "value", value);
        MMessage m_Message = new MMessage(ctx, id, getTrxName(ctx));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id <= 0 && atts.getValue("AD_Message_ID") != null && Integer.parseInt(atts.getValue("AD_Message_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_Message.setAD_Message_ID(Integer.parseInt(atts.getValue("AD_Message_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_Message", m_Message);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_Message.setMsgText(getStringValue(atts, "MsgText"));
        m_Message.setMsgTip(getStringValue(atts, "MsgTip"));
        m_Message.setEntityType(atts.getValue("EntityType"));
        m_Message.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_Message.setValue(value);
        m_Message.setMsgType(atts.getValue("MsgType"));
        if (m_Message.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_Message.getValue(), "Message", m_Message.get_ID(), AD_Backup_ID, Object_Status, "AD_Message", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Message"));
        } else {
            record_log(ctx, 0, m_Message.getValue(), "Message", m_Message.get_ID(), AD_Backup_ID, Object_Status, "AD_Message", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Message"));
            throw new POSaveFailedException("Failed to save message.");
        }
    } else {
        element.skip = true;
    }
}
Also used : MMessage(org.compiere.model.MMessage) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Aggregations

MMessage (org.compiere.model.MMessage)3 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 MNote (org.compiere.model.MNote)1 M_Element (org.compiere.model.M_Element)1 Attributes (org.xml.sax.Attributes)1