IDEMPIERE-460 Integrate and migrate 3e services. Fixed lookup. Refactoring and cleanup.

This commit is contained in:
Heng Sin Low 2013-02-19 21:25:15 +08:00
parent eac774fb67
commit e436719065
18 changed files with 1667 additions and 1280 deletions

View File

@ -13,5 +13,10 @@ import org.idempiere.adInterface.x10.CompositeResponsesDocument;
@SOAPBinding(style=Style.RPC,use=Use.LITERAL,parameterStyle=ParameterStyle.WRAPPED)
public interface CompositeService {
/**
*
* @param reqs
* @return CompositeResponsesDocument
*/
public CompositeResponsesDocument compositeOperation(CompositeRequestDocument reqs);
}

View File

@ -14,7 +14,7 @@
package com.trekglobal.ws;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import javax.jws.WebService;
@ -26,8 +26,6 @@ import org.idempiere.adInterface.x10.CompositeRequestDocument;
import org.idempiere.adInterface.x10.CompositeResponse;
import org.idempiere.adInterface.x10.CompositeResponses;
import org.idempiere.adInterface.x10.CompositeResponsesDocument;
import org.idempiere.adInterface.x10.DataField;
import org.idempiere.adInterface.x10.ModelCRUD;
import org.idempiere.adInterface.x10.ModelCRUDRequest;
import org.idempiere.adInterface.x10.ModelCRUDRequestDocument;
import org.idempiere.adInterface.x10.ModelRunProcessRequest;
@ -41,7 +39,6 @@ import org.idempiere.adInterface.x10.RunProcessResponseDocument;
import org.idempiere.adInterface.x10.StandardResponse;
import org.idempiere.adInterface.x10.StandardResponseDocument;
import org.idempiere.adInterface.x10.WindowTabDataDocument;
import org.idempiere.adinterface.CompiereService;
import org.idempiere.adinterface.ModelADServiceImpl;
import org.idempiere.webservices.AbstractService;
@ -59,60 +56,71 @@ public class CompositeServiceImpl extends AbstractService implements CompositeSe
private static String webServiceName = new String("CompositeInterface");
public CompositeServiceImpl() {
log.info("Creating session object BiziInterface");
if (log.isLoggable(Level.INFO))
log.info("Creating session object compositeInterface");
}
/**
* @see CompositeService#compositeOperation(CompositeRequestDocument)
*/
@Override
public CompositeResponsesDocument compositeOperation(CompositeRequestDocument reqs) {
boolean connected = getCompiereService().isConnected();
CompiereService m_cs = getCompiereService();
try {
if (!connected)
getCompiereService().connect();
CompositeResponsesDocument ret = CompositeResponsesDocument.Factory.newInstance();
CompositeResponses resps = ret.addNewCompositeResponses();
CompositeResponsesDocument ret = CompositeResponsesDocument.Factory.newInstance();
CompositeResponses resps = ret.addNewCompositeResponses();
CompositeRequest req = reqs.getCompositeRequest();
String serviceType = req.getServiceType();
ADLoginRequest reqlogin = req.getADLoginRequest();
String err = login(reqlogin, webServiceName, "composite", serviceType);
if (err != null && err.length() > 0) {
CompositeResponse resp = resps.addNewCompositeResponse();
StandardResponse stdResp = resp.addNewStandardResponse();
stdResp.setError(err);
stdResp.setIsError(true);
return ret;
}
ModelADServiceImpl modelADService = new ModelADServiceImpl(ctx);
String trxName = m_cs.getM_trx_name();
trxName = Trx.createTrxName("ws_biziInterface");
Trx trx = Trx.get(trxName, true);
modelADService.setLocalTrxName(trxName);
Operations operationsArr[] = req.getOperationsArray();
for (Operations operations : operationsArr) {
Operation operationArr[] = operations.getOperationArray();
if (operationArr.length > 0) {
CompositeResponse compResp = resps.addNewCompositeResponse();
ArrayList<StandardResponse> respAggregator = new ArrayList<StandardResponse>();
boolean isSuccess = performOperations(trx, operationArr, modelADService, compResp, respAggregator, reqlogin);
// Committing after each operation set
if (isSuccess) {
commitTrx(trx, compResp, respAggregator, "Cannot commit at end of process", false);
}
CompositeRequest req = reqs.getCompositeRequest();
String serviceType = req.getServiceType();
ADLoginRequest reqlogin = req.getADLoginRequest();
String err = login(reqlogin, webServiceName, "composite", serviceType);
if (err != null && err.length() > 0) {
CompositeResponse resp = resps.addNewCompositeResponse();
StandardResponse stdResp = resp.addNewStandardResponse();
stdResp.setError(err);
stdResp.setIsError(true);
return ret;
}
ModelADServiceImpl modelADService = new ModelADServiceImpl(ctx);
String trxName = Trx.createTrxName(webServiceName);
Trx trx = Trx.get(trxName, true);
try {
modelADService.setLocalTrxName(trxName);
Operations operationsArr[] = req.getOperationsArray();
for (Operations operations : operationsArr) {
Operation operationArr[] = operations.getOperationArray();
if (operationArr.length > 0) {
CompositeResponse compResp = resps.addNewCompositeResponse();
ArrayList<StandardResponse> respAggregator = new ArrayList<StandardResponse>();
boolean isSuccess = performOperations(trx, operationArr, modelADService, compResp, respAggregator, reqlogin);
// Committing after each operation set
if (isSuccess) {
commitTrx(trx, compResp, respAggregator, "Cannot commit at end of process", false);
}
}
}
} finally {
trx.close();
}
return ret;
} finally {
if (!connected)
getCompiereService().disconnect();
}
trx.close();
return ret;
}
/**
@ -260,6 +268,12 @@ public class CompositeServiceImpl extends AbstractService implements CompositeSe
return wrapperDoc;
}
/**
*
* @param ctx
* @param crud
*/
/*
public void resolveContextCRUD(Properties ctx, ModelCRUD crud) {
DataField fields[] = crud.getDataRow().getFieldArray();
for (DataField field : fields) {
@ -271,7 +285,7 @@ public class CompositeServiceImpl extends AbstractService implements CompositeSe
field.setVal(val);
}
}
}
}*/
/**
* Rollback and set error on response

View File

@ -46,6 +46,6 @@ public class CompiereDataSourceFactory
if(ri.getReportViewID() > 0)
return new ReportViewDataSource(ctx, pi, params);
return new DBDataSource(ctx, ri, params);
return new DBDataSource(ctx, ri, params);
}
}

View File

@ -76,7 +76,7 @@ public class ReportViewDataSource extends compiereDataSource
public Object getFieldValue(JRField field) throws JRException
{
PrintDataElement pde = (PrintDataElement)m_printData.getNode(field.getName());
if(pde == null || pde.isNull())
if(pde == null || pde.isNull())
return null;
if(pde.isDate())

View File

@ -1,44 +0,0 @@
/**
* reportServer for JasperReport.
* Copyright (C) 2004 Peter Shen.
* Shanghai, China.
* Email: zpshen@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contributor: Marco LOMBARDO, Compilo subAdministrator.
* lombardo@mayking.com, mar9000@gmail.com
* Italy.
**/
package net.sf.compilo.data;
/**
* @author Peter Shen
* @version $Id: sqlProcessor.java,v 1.1 2005/07/15 10:29:40 pshen Exp $
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class sqlProcessor
{
/**
*
*/
public sqlProcessor()
{
super();
// TODO Auto-generated constructor stub
}
}

View File

@ -40,7 +40,7 @@ public class FileFilter implements FilenameFilter
public FileFilter(String reportStart, File directory, String[] extension)
{
this.reportStart = reportStart;
this.directory = directory;
this.directory = directory;
this.extension = extension;
}

View File

@ -150,10 +150,6 @@ public class ReportInfo
JasperReport res = null;
try
{
String compiere_home = (String)System.getProperty("COMPIERE_HOME");
// compiere_home = "C:/compiere/acompiere2/";
//log.info( "compiere_home = "+compiere_home);
System.setProperty("jasper.reports.compile.class.path", compiere_home+"/lib/reporttools.jar;"+compiere_home+"/lib/Compiere.jar");
JasperCompileManager.compileReportToFile( reportFile.getAbsolutePath(), jasperFile.getAbsolutePath());
jasperFile.setLastModified( reportFile.lastModified());
res = (JasperReport)JRLoader.loadObjectFromFile(jasperFile.getAbsolutePath());
@ -235,49 +231,6 @@ public class ReportInfo
}
log.info("Get ReportDefinition-" + this.toString());
}
/*
private void getResource()
{
// Resources
File[] resources =
reportInfo.getReportFile().getParentFile().listFiles(
new FileFilter( jasperName, reportInfo.getReportFile().getParentFile(), ".properties"));
File resFile = null;
// try baseName + "_" + language
for( int i=0; i<resources.length; i++)
{
if ( resources[i].getName().equals( jasperName+currLang.getLocale().getLanguage()+".properties"))
{
resFile=resources[i];
break;
}
}
if (resFile==null)
{
// try baseName only
for( int i=0; i<resources.length; i++)
{
if ( resources[i].getName().equals( jasperName+".properties"))
{
resFile=resources[i];
break;
}
}
}
if (resFile!=null)
{
try
{
PropertyResourceBundle res = new PropertyResourceBundle( new FileInputStream(resFile));
m_Param.put("RESOURCE", res);
}
catch (IOException e)
{}
}
}
*/
protected boolean isDirty()
{

View File

@ -62,7 +62,7 @@ public class ReportPool
}
*/
ReportInfo reportinfo;
reportinfo = loadReport(AD_Process_ID);
reportinfo = loadReport(AD_Process_ID);
return reportinfo;
}

View File

@ -41,6 +41,7 @@ import org.compiere.process.ProcessInfo;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Language;
/**
@ -52,17 +53,12 @@ import org.compiere.util.Language;
*/
public class ReportProcessor
{
public static final String REPORT_PATH__fix = "c:/compiere/compiere-all/reports";
public static File REPORT_HOME = null;
private static CLogger log = CLogger.getCLogger(ReportProcessor.class);
static
{
String reportPath = REPORT_PATH__fix;// "c:/compiere/compiere-all/reports";//System.getProperty("REPORT_HOME");
if (reportPath == null || reportPath.length() == 0)
reportPath = System.getProperty("COMPIERE_HOME")+ System.getProperty("file.separator")+ "reports";
//System.setProperty("jasper.reports.compiler.class", "net.sf.jasperreports.engine.design.JRCompiler");
String reportPath = Ini.getAdempiereHome();
String classpath = Thread.currentThread().getContextClassLoader().getResource("net/sf/jasperreports/engine").toString();
System.setProperty("jasper.reports.compile.temp", reportPath);
System.setProperty("jasper.reports.compile.class.path", classpath.split("file:/")[1].split("!")[0]);
@ -101,25 +97,21 @@ public class ReportProcessor
addProcessParameters( m_AD_PInstance_ID, m_Param);
m_Param.put("RECORD_ID", new Integer( m_Record_ID));
// Marco LOMBARDO: REPORT_HOME used to express subreports path.
m_Param.put("REPORT_HOME", REPORT_PATH__fix ); //System.getProperty("REPORT_HOME"));
m_Param.put("REPORT_HOME", REPORT_HOME);
// End Marco LOMBARDO.
Language currLang = Env.getLanguage(Env.getCtx());
m_Param.put("CURRENT_LANG", currLang.getAD_Language());
java.sql.Connection conn = DB.getConnectionRO();
m_Param.put("REPORT_CONNECTION", conn ); //DB_CONN
m_Param.put("DB_CONN", conn );
System.out.println( "REPORT_CONNECTION = "+conn.toString() );
log.saveError("REPORT_CONNECTION = "+conn.toString(), "");
//System.out.println( "REPORT_HOME = "+System.getProperty("REPORT_HOME") );
java.sql.Connection conn = DB.getConnectionRO();
m_Param.put("REPORT_CONNECTION", conn ); //DB_CONN
m_Param.put("DB_CONN", conn );
// fill report
compiereDataSource ds = null;
try
{
compiereDataSource ds = CompiereDataSourceFactory.createDataSource(m_ctx, reportInfo, m_pi, m_Param);
//compiereDataSource ds = new compiereDataSource (m_ctx, reportInfo.getJasperReport());
ds = CompiereDataSourceFactory.createDataSource(m_ctx, reportInfo, m_pi, m_Param);
m_jasperPrint = JasperFillManager.fillReport( reportInfo.getJasperReport(), m_Param, ds);
ds.close();
log.finest("ReportProcessor.fillReport");
}
@ -132,6 +124,11 @@ public class ReportProcessor
{
e.printStackTrace();
}
finally
{
if (ds != null)
ds.close();
}
}
else
System.out.println("Error:" + reportInfo.getErrorMsg());

View File

@ -1,3 +1,14 @@
/******************************************************************************
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.adinterface;
import org.compiere.model.Lookup;
@ -18,7 +29,13 @@ public class ADLookup {
protected static CLogger log = CLogger.getCLogger(ADLookup.class);
/**
* @param lvs
* @param lookup
* @param isMandatory
* @param isReadOnly
* @param isShortList
*/
public static void fillLookupValues( LookupValues lvs, Lookup lookup, boolean isMandatory, boolean isReadOnly, boolean isShortList) // IDEMPIERE 90
{

View File

@ -1,3 +1,14 @@
/******************************************************************************
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.adinterface;
import java.sql.PreparedStatement;
@ -18,6 +29,11 @@ import org.compiere.util.KeyNamePair;
import org.compiere.util.Language;
import org.compiere.util.Login;
/**
* @author deepak
* @author hengsin
*
*/
public class CompiereService {
private static CLogger log = CLogger.getCLogger(CompiereService.class);
@ -25,17 +41,16 @@ public class CompiereService {
public final static String datePattern = "dd-MM-yyyy";
private Properties m_ctx;
private String m_trx_name;
private int m_AD_Client_ID;
private int m_AD_Org_ID;
private int m_AD_User_ID;
private int m_AD_Role_ID;
private int m_AD_Warehouse_ID;
private String m_Lang;
private String m_User;
private int m_M_Warehouse_ID;
private String m_locale;
private String m_userName;
private boolean LoggedIn = false;
private boolean m_loggedin = false;
/** Localized Date format */
@ -66,83 +81,109 @@ public class CompiereService {
/** Localized Quantity format */
public DecimalFormat modelQuantityFormat = null;
private Language m_lang;
private Language m_language;
public final String dateFormatOnlyForCtx = "yyyy-MM-dd";
public int getM_AD_Client_ID() {
private boolean m_connected;
/**
*
* @return AD_Client_ID of current request
*/
public int getAD_Client_ID() {
return m_AD_Client_ID;
}
public void setM_AD_Client_ID(int client_ID) {
m_AD_Client_ID = client_ID;
}
public int getM_AD_Org_ID() {
/**
*
* @return AD_Org_ID of current request
*/
public int getAD_Org_ID() {
return m_AD_Org_ID;
}
public void setM_AD_Org_ID(int org_ID) {
m_AD_Org_ID = org_ID;
}
public Properties getM_ctx() {
/**
*
* @return context of current request
*/
public Properties getCtx() {
return m_ctx;
}
public void setM_ctx(Properties m_ctx) {
this.m_ctx = m_ctx;
}
public String getM_trx_name() {
return m_trx_name;
}
public void setM_trx_name(String m_trx_name) {
this.m_trx_name = m_trx_name;
}
/**
* default constructor
*/
public CompiereService()
{
m_trx_name= null; //Trx.createTrxName();
m_ctx = new Properties();
LoggedIn = false;
m_loggedin = false;
m_connected = false;
}
/**
* setup request
*/
public void connect()
{
CompiereUtil.initWeb();
if (!m_connected)
{
CompiereUtil.initWeb();
ServerContext.setCurrentInstance(m_ctx);
Env.setContext( m_ctx, "#AD_Language", "en_US" );
m_lang = Language.getLanguage("en_US");
m_ctx = new Properties();
m_connected = true;
// These variables are needed for ADClient.exe
Language m_lang2 = Language.getLanguage("pl_PL");
ServerContext.setCurrentInstance(m_ctx);
Env.setContext( m_ctx, "#AD_Language", "en_US" );
m_language = Language.getLanguage("en_US");
// These variables are needed for ADClient.exe
Language m_lang2 = Language.getLanguage("pl_PL");
dateFormat = new SimpleDateFormat( datePattern );
dateTimeFormat = new SimpleDateFormat( datePattern );
amountFormat = DisplayType.getNumberFormat(DisplayType.Amount, m_lang2);
integerFormat = DisplayType.getNumberFormat(DisplayType.Integer, m_lang2);
numberFormat = DisplayType.getNumberFormat(DisplayType.Number, m_lang2);
quantityFormat = DisplayType.getNumberFormat(DisplayType.Quantity, m_lang2);
dateFormat = new SimpleDateFormat( datePattern );
dateTimeFormat = new SimpleDateFormat( datePattern );
amountFormat = DisplayType.getNumberFormat(DisplayType.Amount, m_lang2);
integerFormat = DisplayType.getNumberFormat(DisplayType.Integer, m_lang2);
numberFormat = DisplayType.getNumberFormat(DisplayType.Number, m_lang2);
quantityFormat = DisplayType.getNumberFormat(DisplayType.Quantity, m_lang2);
}
}
public Language getM_lang() {
return m_lang;
/**
* cleanup request
*/
public void disconnect()
{
if (m_connected)
{
ServerContext.dispose();
m_ctx = null;
m_loggedin = false;
m_connected = false;
}
}
public void setM_lang(Language m_lang) {
this.m_lang = m_lang;
/**
* @return true if started
*/
public boolean isConnected()
{
return m_connected;
}
/**
* @return Language of current request
*/
public Language getLanguage() {
return m_language;
}
/**
* @return true if already logged in
*/
public boolean isLoggedIn() {
return LoggedIn;
return m_loggedin;
}
/**
@ -170,14 +211,16 @@ public class CompiereService {
+ " AND (o.AD_Client_ID = 0 OR o.AD_Client_ID=c.AD_Client_ID)"
+ " AND c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)"
+ " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_User_ID);
pstmt.setInt(2, AD_Client_ID);
pstmt.setInt(3, AD_Org_ID);
pstmt.setInt(4, AD_Role_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
loginInfo = rs.getString(1);
rs.close();
@ -185,7 +228,9 @@ public class CompiereService {
}
catch (SQLException e)
{
// log.log(Level.SEVERE, "checkLogin", e);
e.printStackTrace();
} finally {
DB.close(rs, pstmt);
}
// not verified
@ -202,16 +247,23 @@ public class CompiereService {
String printer = null;
Login login = new Login(ctx);
login.loadPreferences(org, wh, date, printer);
// Don't Show Acct/Trl Tabs on HTML UI
Env.setContext(ctx, "#ShowAcct", "N");
Env.setContext(ctx, "#ShowTrl", "N");
//
return loginInfo;
} // checkLogin
public boolean login( int AD_User_ID, int AD_Role_ID, int AD_Client_ID, int AD_Org_ID, int AD_Warehouse_ID, String Lang ) {
LoggedIn = false;
String loginInfo = checkLogin (getM_ctx(), AD_User_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID, AD_Warehouse_ID );
/**
*
* @param AD_User_ID
* @param AD_Role_ID
* @param AD_Client_ID
* @param AD_Org_ID
* @param M_Warehouse_ID
* @param Lang
* @return true if login is successful
*/
public boolean login( int AD_User_ID, int AD_Role_ID, int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID, String Lang ) {
m_loggedin = false;
String loginInfo = checkLogin (getCtx(), AD_User_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID, M_Warehouse_ID );
if (loginInfo == null)
return false;
@ -219,75 +271,74 @@ public class CompiereService {
m_AD_Org_ID = AD_Org_ID;
m_AD_User_ID = AD_User_ID;
m_AD_Role_ID = AD_Role_ID;
m_AD_Warehouse_ID = AD_Warehouse_ID;
m_Lang = Lang;
m_User = MUser.getNameOfUser(m_AD_User_ID);
m_M_Warehouse_ID = M_Warehouse_ID;
m_locale = Lang;
m_userName = MUser.getNameOfUser(m_AD_User_ID);
Env.setContext( m_ctx, "#AD_Language", Lang);
m_lang = Language.getLanguage(Lang);
Env.verifyLanguage( getM_ctx(), m_lang );
m_language = Language.getLanguage(Lang);
Env.verifyLanguage( getCtx(), m_language );
modelDateFormat = new SimpleDateFormat( datePattern );
modelDateTimeFormat = new SimpleDateFormat( datePattern );
modelAmountFormat = DisplayType.getNumberFormat(DisplayType.Amount, m_lang);
modelIntegerFormat = DisplayType.getNumberFormat(DisplayType.Integer, m_lang);
modelNumberFormat = DisplayType.getNumberFormat(DisplayType.Number, m_lang);
modelQuantityFormat = DisplayType.getNumberFormat(DisplayType.Quantity, m_lang);
modelAmountFormat = DisplayType.getNumberFormat(DisplayType.Amount, m_language);
modelIntegerFormat = DisplayType.getNumberFormat(DisplayType.Integer, m_language);
modelNumberFormat = DisplayType.getNumberFormat(DisplayType.Number, m_language);
modelQuantityFormat = DisplayType.getNumberFormat(DisplayType.Quantity, m_language);
// Set Date
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat( dateFormatOnlyForCtx );
Env.setContext( getM_ctx(), "#Date", dateFormat4Timestamp.format(ts)+" 00:00:00" ); // JDBC format
log.info(" #Date = "+ Env.getContextAsDate( getM_ctx(), "#Date"));
Env.setContext( getCtx(), "#Date", dateFormat4Timestamp.format(ts)+" 00:00:00" ); // JDBC format
log.info(" #Date = "+ Env.getContextAsDate( getCtx(), "#Date"));
Env.setContext( getM_ctx(), "#M_Warehouse_ID", AD_Warehouse_ID );
Env.setContext(m_ctx, Env.LANGUAGE, m_lang.getAD_Language());
//Env.setContext( getM_ctx(), "#AD_Language", Lang );
Env.setContext( getCtx(), "#M_Warehouse_ID", M_Warehouse_ID );
Env.setContext(m_ctx, Env.LANGUAGE, m_language.getAD_Language());
LoggedIn = true;
m_loggedin = true;
return true;
}
public void setM_AD_User_ID(int m_AD_User_ID) {
this.m_AD_User_ID = m_AD_User_ID;
}
public int getM_AD_User_ID() {
/**
*
* @return AD_User_ID of current request
*/
public int getAD_User_ID() {
return m_AD_User_ID;
}
public void setM_AD_Role_ID(int m_AD_Role_ID) {
this.m_AD_Role_ID = m_AD_Role_ID;
}
public int getM_AD_Role_ID() {
/**
*
* @return AD_Role_ID of current request
*/
public int getAD_Role_ID() {
return m_AD_Role_ID;
}
public void setM_Lang(String m_Lang) {
this.m_Lang = m_Lang;
/**
*
* @return locale code of current request
*/
public String getLocale() {
return m_locale;
}
public String getM_Lang() {
return m_Lang;
/**
*
* @return M_Warehouse_ID of current request
*/
public int getM_Warehouse_ID() {
return m_M_Warehouse_ID;
}
public void setM_AD_Warehouse_ID(int m_AD_Warehouse_ID) {
this.m_AD_Warehouse_ID = m_AD_Warehouse_ID;
}
public int getM_AD_Warehouse_ID() {
return m_AD_Warehouse_ID;
}
public void setUser(String m_User) {
this.m_User = m_User;
}
public String getUser() {
return m_User;
/**
*
* @return logged in user name of current request
*/
public String getUserName() {
return m_userName;
}
}

View File

@ -1,12 +1,20 @@
/******************************************************************************
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.adinterface;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.model.MClient;
import org.compiere.model.MSystem;
import org.compiere.util.CLogger;
@ -15,7 +23,9 @@ public class CompiereUtil {
private static CLogger log = CLogger.getCLogger(CompiereUtil.class);
private static boolean s_initOK = false;
/**
* @return startup idempiere environment if needed
*/
public static boolean initWeb()
{
if (s_initOK)
@ -23,16 +33,8 @@ public class CompiereUtil {
return true;
}
// TODO:
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
try
{
//CLogMgt.setLevel(Level.OFF);
/* ADEMPIERE/COMPIERE */
//s_initOK = Compiere.startup(false);
s_initOK = Adempiere.startup(false);
}
catch (Exception ex)
@ -42,16 +44,6 @@ public class CompiereUtil {
if (!s_initOK)
return false;
// Logging now initiated
//
Properties ctx = new Properties();
@SuppressWarnings("unused")
MClient client = MClient.get(ctx, 0);
@SuppressWarnings("unused")
MSystem system = MSystem.get(ctx);
return s_initOK;
}
}

View File

@ -66,10 +66,10 @@ public class Process {
MProcess process = null;
if (AD_Menu_ID>0 && AD_Process_ID==0 )
process = MProcess.getFromMenu( cs.getM_ctx(), AD_Menu_ID);
process = MProcess.getFromMenu( cs.getCtx(), AD_Menu_ID);
else
if (AD_Menu_ID==0 && AD_Process_ID>0 )
process = new MProcess( cs.getM_ctx(), AD_Process_ID, null);
process = new MProcess( cs.getCtx(), AD_Process_ID, null);
if (process != null)
{
@ -101,7 +101,7 @@ public class Process {
if (para.getDefaultValue().indexOf( "@#Date@")>=0) {
//Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
//String t = Env.getContext( cs.getM_ctx(), "#Date" );
String t= cs.dateFormat.format( Env.getContextAsDate( cs.getM_ctx(), "#Date") );
String t= cs.dateFormat.format( Env.getContextAsDate( cs.getCtx(), "#Date") );
p.setDefaultValue( t ); //cs.dateFormat.format( t ));
}
@ -125,7 +125,7 @@ public class Process {
if (para.getDefaultValue2().indexOf( "@#Date@")>=0) {
//Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
//String t = Env.getContext( cs.getM_ctx(), "#Date" );
String t= cs.dateFormat.format( Env.getContextAsDate( cs.getM_ctx(), "#Date") );
String t= cs.dateFormat.format( Env.getContextAsDate( cs.getCtx(), "#Date") );
p.setDefaultValue2( t ); //cs.dateFormat.format( t ) );
}
}
@ -165,7 +165,7 @@ public class Process {
int m_record_id = rp.getADRecordID();
//WebSessionCtx wsc = WebSessionCtx.get (request);
MProcess process = MProcess.get (m_cs.getM_ctx() , AD_Process_ID);
MProcess process = MProcess.get (m_cs.getCtx() , AD_Process_ID);
// need to check if Role can access
if (process == null)
{
@ -183,13 +183,13 @@ public class Process {
// Requirements
// - the process must be a workflow document
if (process.getAD_Workflow_ID() > 0) {
MWorkflow wf = MWorkflow.get(m_cs.getM_ctx(), process.getAD_Workflow_ID());
MWorkflow wf = MWorkflow.get(m_cs.getCtx(), process.getAD_Workflow_ID());
if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
// - get the table associated with the workflow document
// - set DocAction in such table
// get the PO for the tablename and record ID
MTable table = MTable.get(m_cs.getM_ctx(), wf.getAD_Table_ID());
MTable table = MTable.get(m_cs.getCtx(), wf.getAD_Table_ID());
if (table != null) {
PO po = table.getPO(m_record_id, null);
if (po != null) {
@ -222,8 +222,8 @@ public class Process {
}
//
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID());
pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getM_ctx()));
pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getM_ctx()));
pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getCtx()));
pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getCtx()));
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
if (m_record_id >0)
pi.setRecord_ID( m_record_id );
@ -332,7 +332,7 @@ public class Process {
if (pf.isTableBased())
{
CharArrayWriter wr = new CharArrayWriter();
ok = ReportEngineEx.createEXCEL_HTML_wr( re, m_cs.getM_ctx(), wr, false, re.getPrintFormat().getLanguage() );
ok = ReportEngineEx.createEXCEL_HTML_wr( re, m_cs.getCtx(), wr, false, re.getPrintFormat().getLanguage() );
file_type ="xls";
String data = wr.toString();
if (data!=null)
@ -351,7 +351,7 @@ public class Process {
}
else
{
JasperPrint jp = getJasperReportPrint( m_cs.getM_ctx(), pi);
JasperPrint jp = getJasperReportPrint( m_cs.getCtx(), pi);
//file = File.createTempFile("WProcess", ".pdf");
ByteArrayOutputStream wr = new ByteArrayOutputStream();
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
@ -368,7 +368,7 @@ public class Process {
//file.getAbsolutePath()
// Marker that Process is OK
m_cs.getM_ctx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
m_cs.getCtx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
}
else
{

View File

@ -25,7 +25,6 @@ import java.util.Properties;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
@ -64,6 +63,7 @@ import org.idempiere.adinterface.CompiereService;
*/
public class AbstractService {
private static final String COMPIERE_SERVICE = "CompiereService";
@Resource
protected WebServiceContext ctx;
@ -79,16 +79,16 @@ public class AbstractService {
CompiereService m_cs = getCompiereService();
if (m_cs.isLoggedIn() && m_cs.getM_AD_Client_ID() == loginRequest.getClientID() && loginRequest.getClientID() == Env.getAD_Client_ID(Env.getCtx())
&& m_cs.getM_AD_Org_ID() == loginRequest.getOrgID() && m_cs.getM_AD_Role_ID() == loginRequest.getRoleID()
&& m_cs.getM_AD_Warehouse_ID() == loginRequest.getWarehouseID() && loginRequest.getUser().equals(m_cs.getUser()))
if (m_cs.isLoggedIn() && m_cs.getAD_Client_ID() == loginRequest.getClientID() && loginRequest.getClientID() == Env.getAD_Client_ID(Env.getCtx())
&& m_cs.getAD_Org_ID() == loginRequest.getOrgID() && m_cs.getAD_Role_ID() == loginRequest.getRoleID()
&& m_cs.getM_Warehouse_ID() == loginRequest.getWarehouseID() && loginRequest.getUser().equals(m_cs.getUserName()))
return authenticate(webService, method, serviceType, m_cs); // already logged with same data
String ret =invokeLoginValidator(loginRequest, m_cs.getM_ctx(), null, IWSValidator.TIMING_BEFORE_LOGIN);
String ret =invokeLoginValidator(loginRequest, m_cs.getCtx(), null, IWSValidator.TIMING_BEFORE_LOGIN);
if(ret!=null && ret.length()>0)
return ret;
Login login = new Login(m_cs.getM_ctx());
Login login = new Login(m_cs.getCtx());
KeyNamePair[] roles = login.getRoles(loginRequest.getUser(), loginRequest.getPass());
if (roles != null) {
boolean okrole = false;
@ -112,7 +112,7 @@ public class AbstractService {
if (!okclient)
return "Error logging in - client not allowed for this role";
m_cs.getM_ctx().setProperty("#AD_Client_ID", "" + loginRequest.getClientID());
m_cs.getCtx().setProperty("#AD_Client_ID", "" + loginRequest.getClientID());
KeyNamePair[] orgs = login.getOrgs(new KeyNamePair(loginRequest.getRoleID(), ""));
@ -146,7 +146,7 @@ public class AbstractService {
if (error != null && error.length() > 0)
return error;
int AD_User_ID = Env.getAD_User_ID(m_cs.getM_ctx());
int AD_User_ID = Env.getAD_User_ID(m_cs.getCtx());
if (!m_cs.login(AD_User_ID, loginRequest.getRoleID(), loginRequest.getClientID(), loginRequest.getOrgID(), loginRequest.getWarehouseID(), loginRequest.getLang()))
@ -158,7 +158,7 @@ public class AbstractService {
return "Error logging in - no roles or user/pwd invalid for user " + loginRequest.getUser();
}
ret =invokeLoginValidator(loginRequest, m_cs.getM_ctx(), null, IWSValidator.TIMING_AFTER_LOGIN);
ret =invokeLoginValidator(loginRequest, m_cs.getCtx(), null, IWSValidator.TIMING_AFTER_LOGIN);
if(ret!=null && ret.length()>0)
return ret;
@ -177,7 +177,7 @@ public class AbstractService {
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
MWebService m_webservice = MWebService.get(m_cs.getM_ctx(), webServiceValue);
MWebService m_webservice = MWebService.get(m_cs.getCtx(), webServiceValue);
if (m_webservice == null || !m_webservice.isActive())
return "Web Service " + webServiceValue + " not registered";
@ -192,13 +192,13 @@ public class AbstractService {
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_cs.getM_AD_Client_ID());
pstmt.setInt(1, m_cs.getAD_Client_ID());
pstmt.setInt(2, m_webservice.getWS_WebService_ID());
pstmt.setInt(3, m_webservicemethod.getWS_WebServiceMethod_ID());
pstmt.setString(4, serviceTypeValue);
rs = pstmt.executeQuery();
if (rs.next())
m_webservicetype = new MWebServiceType(m_cs.getM_ctx(), rs, null);
m_webservicetype = new MWebServiceType(m_cs.getCtx(), rs, null);
} catch (Exception e) {
throw new IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName(
"authenticate"));
@ -213,7 +213,7 @@ public class AbstractService {
req.setAttribute("MWebServiceType", m_webservicetype);
String ret=invokeLoginValidator(null, m_cs.getM_ctx(), m_webservicetype, IWSValidator.TIMING_ON_AUTHORIZATION);
String ret=invokeLoginValidator(null, m_cs.getCtx(), m_webservicetype, IWSValidator.TIMING_ON_AUTHORIZATION);
if(ret!=null && ret.length()>0)
return ret;
@ -240,16 +240,14 @@ public class AbstractService {
/**
*
* @return Compiere Service object for current session
* @return Compiere Service object for current request
*/
protected CompiereService getCompiereService() {
HttpServletRequest req = (HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
HttpSession session = req.getSession();
CompiereService m_cs = (CompiereService) session.getAttribute("CompiereServiceBean");
CompiereService m_cs = (CompiereService) req.getAttribute(COMPIERE_SERVICE);
if (m_cs == null) {
m_cs = new CompiereService();
m_cs.connect();
session.setAttribute("CompiereServiceBean", m_cs);
req.setAttribute(COMPIERE_SERVICE, m_cs);
}
return m_cs;
}
@ -394,10 +392,10 @@ public class AbstractService {
if (indDot == -1) {
if (varName.charAt(0) == '#') {
varName = varName.substring(1);
val = getCompiereService().getM_ctx().getProperty(varName);
val = getCompiereService().getCtx().getProperty(varName);
} else {
// If there is no table name, then it should be
// premitive data type
// primitive data type
if (po != null && poInfo.getColumnIndex(varName)!=-1)
val = po.get_Value(varName);

View File

@ -1,3 +1,16 @@
/******************************************************************************
* Copyright (C) 2012 Trek Global *
* Product: iDempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.webservices;
import org.osgi.framework.BundleActivator;

View File

@ -1,3 +1,16 @@
/******************************************************************************
* Copyright (C) 2012 Trek Global *
* Product: iDempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.webservices;
import java.util.Map;
@ -10,6 +23,11 @@ import org.idempiere.webservices.fault.IdempiereServiceFault;
import org.idempiere.adInterface.x10.ADLoginRequest;
import org.idempiere.adInterface.x10.DataField;
/**
*
* @author deepak
*
*/
public interface IWSValidator {
public static final int TIMING_BEFORE_PARSE=1;
public static final int TIMING_AFTER_PARSE=2;
@ -23,6 +41,25 @@ public interface IWSValidator {
public static final int TIMING_BEFORE_PROCESS=8;
public static final int TIMING_AFTER_PROCESS=9;
/**
*
* @param po
* @param m_webserviceType
* @param fields
* @param time
* @param trxName
* @param requestCtx
* @throws IdempiereServiceFault
*/
public void validate(PO po,MWebServiceType m_webserviceType,DataField[] fields,int time,String trxName,Map<String, Object> requestCtx) throws IdempiereServiceFault;
/**
*
* @param loginRequest
* @param ctx
* @param m_webserviceType
* @param time
* @throws IdempiereServiceFault
*/
public void login(ADLoginRequest loginRequest,Properties ctx,MWebServiceType m_webserviceType,int time) throws IdempiereServiceFault;
}

View File

@ -1,3 +1,16 @@
/******************************************************************************
* Copyright (C) 2012 Trek Global *
* Product: iDempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.webservices.fault;
import javax.xml.namespace.QName;