public void createMRPMessage(final String code) {
   final I_AD_Message message =
       InterfaceWrapperHelper.newInstance(I_AD_Message.class, contextProvider);
   InterfaceWrapperHelper.setValue(message, "AD_Client_ID", 0);
   message.setAD_Org_ID(0);
   message.setValue(code);
   message.setMsgText(code);
   InterfaceWrapperHelper.save(message);
 }
  @Override
  public I_AD_Note createMRPNote() {
    final Properties ctx = getCtx();
    final I_AD_Org org = getAD_Org_ToUse();
    final int AD_Org_ID = org == null ? 0 : org.getAD_Org_ID();
    final I_M_Warehouse warehouse = getM_Warehouse_ToUse();
    final I_S_Resource plant = getPlant_ToUse();
    final I_M_Product product = getM_Product_ToUse();
    final int productPlanningId = getPP_Product_Planning_ID_ToUse();
    final int panner_AD_User_ID = getPlanner_AD_Use_ID_ToUse();

    //
    // Note's TextMsg
    final I_AD_Message adMessageToUse = getMRPCode_AD_Message_ToUse();
    final StringBuilder noteTextMsg = new StringBuilder();
    noteTextMsg
        .append(adMessageToUse.getValue())
        .append(" - ")
        .append(messagesBL.getMsg(ctx, adMessageToUse.getValue()));

    //
    // Note's Reference text
    final String noteReference;
    if (product != null) {
      noteReference =
          messagesBL.translate(ctx, "M_Product_ID")
              + ": "
              + product.getValue()
              + " "
              + product.getName();
    } else {
      noteReference = "";
    }

    //
    // Append DocumentNos to note's TextMsg
    final Set<String> documentNos = getDocumentNos_ToUse();
    if (documentNos != null && !documentNos.isEmpty()) {
      final String documentNoPropertyName =
          messagesBL.translate(ctx, I_PP_Order.COLUMNNAME_DocumentNo);
      for (final String documentNo : documentNos) {
        noteTextMsg.append("\n" + documentNoPropertyName + ":" + documentNo);
      }
    }

    //
    // Append additional parameters to TextMsg
    final String parametersStr = getParametersAsString();
    if (!Check.isEmpty(parametersStr, true)) {
      noteTextMsg.append("\n").append(parametersStr);
    }

    //
    // Apppend Comment (if any) to note's TextMsg
    final String comment = getComment_ToUse();
    if (!Check.isEmpty(comment, true)) {
      noteTextMsg.append("\n").append(comment);
    }

    //
    // Append Exception (if any)
    final Exception exception = getException_ToUse();
    if (exception != null) {
      String exceptionStr = exception.getLocalizedMessage();
      if (exceptionStr == null || exceptionStr.length() <= 5) {
        // comment to small, better use whole exception string
        exceptionStr = exception.toString();
      }

      noteTextMsg.append("\nException: ").append(exceptionStr);

      // NOTE: since the exception is not logged anywhere, we are printing here to console
      // FIXME: create an AD_Issue and link it to create AD_Note.
      logger.log(Level.WARNING, exception.getLocalizedMessage(), exception);
    }

    //
    // Create AD_Note and return it
    {
      final I_PP_MRP mrp = getPP_MRP_ToUse();
      final int mrpId = mrp == null ? 0 : mrp.getPP_MRP_ID();

      final I_AD_Note note =
          InterfaceWrapperHelper.create(ctx, I_AD_Note.class, ITrx.TRXNAME_ThreadInherited);
      note.setAD_Org_ID(AD_Org_ID);
      note.setAD_Message_ID(adMessageToUse.getAD_Message_ID());
      note.setAD_User_ID(panner_AD_User_ID);

      // NOTE: we always shall set the AD_Table_ID=PP_MRP because else the MRP cleanup won't delete
      // this note (see org.eevolution.mrp.api.impl.MRPNoteDAO.deleteMRPNotes(IMRPContext))
      note.setAD_Table_ID(InterfaceWrapperHelper.getTableId(I_PP_MRP.class));

      if (mrpId > 0) {
        note.setRecord_ID(mrpId);
      }
      note.setM_Warehouse(warehouse);
      note.setPP_Plant(plant);
      note.setM_Product(product);
      note.setPP_Product_Planning_ID(productPlanningId);
      note.setReference(noteReference);
      note.setTextMsg(noteTextMsg.toString());
      InterfaceWrapperHelper.save(note);
      return note;
    }
  }
 @Override
 public int retrieveIdByValue(@CacheCtx final Properties ctx, final String value) {
   final I_AD_Message msg = retrieveByValue(ctx, value);
   if (msg == null) return 0;
   return msg.getAD_Message_ID();
 }