General Code

From iDempiere en
Revision as of 16:53, 24 August 2015 by Ngordon7000 (talk | contribs)


Chat

Quickly add a chat to any PO (table) record.

package za.co.ntier.common;

import java.util.Properties;
import java.util.logging.Level;

import org.compiere.model.MChat;
import org.compiere.model.MChatEntry;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.util.CLogger;
import org.compiere.util.Env;

/**
 * @author nTier Software Services ngordon7000
 * Date: 29 Jun 2015
 * Description:	Chat support
 */
public class NTierChatUtils {
	
	/** Logger */
	private static CLogger log = CLogger.getCLogger(NTierChatUtils.class);
	
	/**
	 */
	public static MChat getChat(Properties ctx, String trxName, 
			PO po) {
		final String whereClause = "AD_Client_ID=? and AD_Table_ID=? AND Record_ID=? ";
		MChat retValue = new Query(ctx, MChat.Table_Name, whereClause,
				trxName).setParameters(Env.getAD_Client_ID(ctx), po.get_Table_ID(), po.get_ID())
				.firstOnly();
		return retValue;
	}
	
	/**
	 * Add chat
	 */
	public static void addChat(Properties ctx, String trxName, 
			PO po, String comments) {
		try {
			String descr = "";
			descr = comments;
			descr = NTierStringUtils.left(descr, 255);
			MChat chat = getChat(ctx, trxName, po);
			if (chat == null) {
				chat = new MChat (ctx, po.get_Table_ID(), po.get_ID(), descr, trxName);
				chat.saveEx(trxName);
			}
			log.info(String.format("Chat - %s - '%s'", po.get_TableName(), descr));
			MChatEntry chatEntry = new MChatEntry(chat, descr);
			chatEntry.saveEx(trxName);
		} catch (Exception e) {
			log.log(Level.SEVERE, "^^^", e);
			log.info(String.format("^^^ Failed to save chat record"));
		}
	}
}

Start a process (or report)

  • See FinReportJasper in the base code, for an example of how this is done.

Database

Call a database procedure

  • From FinReportJasper in the base
// CarlosRuiz - globalqss - allow procedure preprocess
	    if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
			//  execute on this thread/connection
			String sql = "{call " + proc.getProcedureName() + "(?)}";
			CallableStatement cstmt = null;
			try
			{
				cstmt = DB.prepareCall(sql);	//	ro??
				cstmt.setInt(1, getAD_PInstance_ID());
				cstmt.executeUpdate();
			}
			catch (Exception e)
			{
				log.log(Level.SEVERE, sql, e);
				poInfo.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
			}
			finally
			{
				DB.close(cstmt);
				cstmt = null;
			}
	    }

Credits

Initial contribution by: nTier Software Services http://www.ntier.co.za ngordon7000

Add your credit here.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.