IDEMPIERE-3394 Allow defining web service type in System and extend in Tenant

This commit is contained in:
Carlos Ruiz 2017-06-13 17:58:02 +02:00
parent 361c190a06
commit 8615b92609
4 changed files with 144 additions and 144 deletions

View File

@ -0,0 +1,39 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-3394 Allow defining web service type in System and extend in Tenant
-- Jun 13, 2017 4:19:26 PM CEST
UPDATE AD_Column SET DefaultValue='@#AD_Client_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 16:19:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56766
;
-- Jun 13, 2017 4:19:38 PM CEST
UPDATE AD_Column SET DefaultValue='@#AD_Org_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 16:19:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56767
;
-- Jun 13, 2017 5:54:59 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:54:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56734
;
-- Jun 13, 2017 5:55:04 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:55:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56735
;
-- Jun 13, 2017 5:55:21 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:55:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56746
;
-- Jun 13, 2017 5:55:28 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:55:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56747
;
-- Jun 13, 2017 5:55:44 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:55:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56756
;
-- Jun 13, 2017 5:55:51 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_DATE('2017-06-13 17:55:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56758
;
SELECT register_migration_script('201706131623_IDEMPIERE-3394.sql') FROM dual
;

View File

@ -0,0 +1,36 @@
-- IDEMPIERE-3394 Allow defining web service type in System and extend in Tenant
-- Jun 13, 2017 4:19:26 PM CEST
UPDATE AD_Column SET DefaultValue='@#AD_Client_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 16:19:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56766
;
-- Jun 13, 2017 4:19:38 PM CEST
UPDATE AD_Column SET DefaultValue='@#AD_Org_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 16:19:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56767
;
-- Jun 13, 2017 5:54:59 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:54:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56734
;
-- Jun 13, 2017 5:55:04 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:55:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56735
;
-- Jun 13, 2017 5:55:21 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:55:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56746
;
-- Jun 13, 2017 5:55:28 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:55:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56747
;
-- Jun 13, 2017 5:55:44 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Client_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:55:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56756
;
-- Jun 13, 2017 5:55:51 PM CEST
UPDATE AD_Column SET DefaultValue='@AD_Org_ID@', IsToolbarButton='N',Updated=TO_TIMESTAMP('2017-06-13 17:55:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56758
;
SELECT register_migration_script('201706131623_IDEMPIERE-3394.sql') FROM dual
;

View File

@ -29,13 +29,12 @@
package org.compiere.model; package org.compiere.model;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -51,10 +50,10 @@ public class MWebServiceType extends X_WS_WebServiceType
/** /**
* *
*/ */
private static final long serialVersionUID = 134887822892217528L; private static final long serialVersionUID = 7216001796414414950L;
/** Parameters */ /** Parameters */
private X_WS_WebService_Para[] m_para = null; private MWebServicePara[] m_para = null;
/** Allowed input columns */ /** Allowed input columns */
private String[] m_inputcolumnnames = null; private String[] m_inputcolumnnames = null;
@ -75,34 +74,17 @@ public class MWebServiceType extends X_WS_WebServiceType
* @param requery requery * @param requery requery
* @return array of methods * @return array of methods
*/ */
public X_WS_WebService_Para[] getParameters (boolean requery) public MWebServicePara[] getParameters (boolean requery)
{ {
if (m_para != null && !requery) if (m_para != null && !requery)
return m_para; return m_para;
String sql = "SELECT * FROM WS_WebService_Para WHERE WS_WebServiceType_ID=? AND IsActive='Y' ORDER BY ParameterName"; List<MWebServicePara> list = new Query(getCtx(), MWebServicePara.Table_Name,
ArrayList<X_WS_WebService_Para> list = new ArrayList<X_WS_WebService_Para>(); "WS_WebService_Para.WS_WebServiceType_ID=? AND WS_WebService_Para.AD_Client_ID=WS_WebServiceType.AD_Client_ID", get_TrxName())
PreparedStatement pstmt = null; .addJoinClause("JOIN WS_WebServiceType ON (WS_WebServiceType.WS_WebServiceType_ID=WS_WebService_Para.WS_WebServiceType_ID)")
ResultSet rs = null; .setOnlyActiveRecords(true)
try .setParameters(getWS_WebServiceType_ID())
{ .list();
pstmt = DB.prepareStatement (sql, get_TrxName()); m_para = new MWebServicePara[list.size ()];
pstmt.setInt (1, getWS_WebServiceType_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new X_WS_WebService_Para (getCtx(), rs, get_TrxName()));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
m_para = new X_WS_WebService_Para[list.size ()];
list.toArray (m_para); list.toArray (m_para);
return m_para; return m_para;
} // getParameters } // getParameters
@ -135,36 +117,22 @@ public class MWebServiceType extends X_WS_WebServiceType
{ {
if (m_inputcolumnnames != null && !requery) if (m_inputcolumnnames != null && !requery)
return m_inputcolumnnames; return m_inputcolumnnames;
String sql = "SELECT c.ColumnName FROM WS_WebServiceFieldInput f, AD_Column c " + final String sql = ""
"WHERE f.WS_WebServiceType_ID=? " + + "SELECT c.ColumnName FROM WS_WebServiceFieldInput f "
"AND c.AD_Column_ID=f.AD_Column_ID " + + " JOIN AD_Column c ON (c.AD_Column_ID=f.AD_Column_ID) "
"AND c.IsActive='Y' " + + " JOIN WS_WebServiceType t ON t.WS_WebServiceType_ID=f.WS_WebServiceType_ID "
"AND f.IsActive='Y' " + + "WHERE f.WS_WebServiceType_ID=? "
"ORDER BY c.ColumnName"; + " AND f.AD_Client_ID=t.AD_Client_ID "
ArrayList<String> list = new ArrayList<String>(); + " AND c.IsActive='Y' "
PreparedStatement pstmt = null; + " AND f.IsActive='Y' "
ResultSet rs = null; + "ORDER BY c.ColumnName";
try List<Object> list = DB.getSQLValueObjectsEx(get_TrxName(), sql, getWS_WebServiceType_ID());
{ if (list == null) {
pstmt = DB.prepareStatement (sql, get_TrxName()); m_inputcolumnnames = new String[0];
pstmt.setInt (1, getWS_WebServiceType_ID()); } else {
rs = pstmt.executeQuery (); m_inputcolumnnames = new String[list.size ()];
while (rs.next ()) list.toArray (m_inputcolumnnames);
list.add (rs.getString(1));
} }
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
m_inputcolumnnames = new String[list.size ()];
list.toArray (m_inputcolumnnames);
return m_inputcolumnnames; return m_inputcolumnnames;
} // getInputColumnNames } // getInputColumnNames
@ -196,36 +164,22 @@ public class MWebServiceType extends X_WS_WebServiceType
{ {
if (m_outputcolumnnames != null && !requery) if (m_outputcolumnnames != null && !requery)
return m_outputcolumnnames; return m_outputcolumnnames;
String sql = "SELECT c.ColumnName FROM WS_WebServiceFieldOutput f, AD_Column c " + final String sql = ""
"WHERE f.WS_WebServiceType_ID=? " + + "SELECT c.ColumnName FROM WS_WebServiceFieldOutput f "
"AND c.AD_Column_ID=f.AD_Column_ID " + + " JOIN AD_Column c ON (c.AD_Column_ID=f.AD_Column_ID) "
"AND c.IsActive='Y' " + + " JOIN WS_WebServiceType t ON t.WS_WebServiceType_ID=f.WS_WebServiceType_ID "
"AND f.IsActive='Y' " + + "WHERE f.WS_WebServiceType_ID=? "
"ORDER BY c.ColumnName"; + " AND f.AD_Client_ID=t.AD_Client_ID "
ArrayList<String> list = new ArrayList<String>(); + " AND c.IsActive='Y' "
PreparedStatement pstmt = null; + " AND f.IsActive='Y' "
ResultSet rs = null; + "ORDER BY c.ColumnName";
try List<Object> list = DB.getSQLValueObjectsEx(get_TrxName(), sql, getWS_WebServiceType_ID());
{ if (list == null) {
pstmt = DB.prepareStatement (sql, get_TrxName()); m_outputcolumnnames = new String[0];
pstmt.setInt (1, getWS_WebServiceType_ID()); } else {
rs = pstmt.executeQuery (); m_outputcolumnnames = new String[list.size ()];
while (rs.next ()) list.toArray (m_outputcolumnnames);
list.add (rs.getString(1));
} }
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
m_outputcolumnnames = new String[list.size ()];
list.toArray (m_outputcolumnnames);
return m_outputcolumnnames; return m_outputcolumnnames;
} // getOutputColumnNames } // getOutputColumnNames
@ -299,41 +253,28 @@ public class MWebServiceType extends X_WS_WebServiceType
m_keyColumns = new ArrayList<String>(); m_keyColumns = new ArrayList<String>();
else else
m_keyColumns.clear(); m_keyColumns.clear();
List<X_WS_WebServiceFieldInput> list = new Query(getCtx(), X_WS_WebServiceFieldInput.Table_Name,
"WS_WebServiceFieldInput.WS_WebServiceType_ID=? AND WS_WebServiceFieldInput.AD_Client_ID=WS_WebServiceFieldInput.AD_Client_ID",
String sql = "SELECT coalesce(c.ColumnName,f.ColumnName),f.* FROM WS_WebServiceFieldInput f left join AD_Column c on c.AD_Column_ID=f.AD_Column_ID " + get_TrxName())
"WHERE f.WS_WebServiceType_ID=? " + .addJoinClause("JOIN WS_WebServiceType ON (WS_WebServiceType.WS_WebServiceType_ID=WS_WebServiceFieldInput.WS_WebServiceType_ID)")
"AND (c.IsActive='Y' OR c.IsActive is null)" + .addJoinClause("LEFT JOIN AD_Column ON (AD_Column.AD_Column_ID=WS_WebServiceFieldInput.AD_Column_ID)")
"AND f.IsActive='Y' " + .setOnlyActiveRecords(true)
"ORDER BY c.ColumnName"; .setOrderBy("AD_Column.ColumnName")
PreparedStatement pstmt = null; .setParameters(getWS_WebServiceType_ID())
ResultSet rs = null; .list();
try for (X_WS_WebServiceFieldInput inputField : list) {
{ String colName = inputField.getColumnName();
pstmt = DB.prepareStatement (sql, get_TrxName()); if (inputField.getAD_Column_ID() > 0) {
pstmt.setInt (1, getWS_WebServiceType_ID()); MColumn col = MColumn.get(getCtx(), inputField.getAD_Column_ID());
rs = pstmt.executeQuery (); if (! col.isActive()) {
while (rs.next ()) continue;
{ }
String colName = rs.getString(1); colName = col.getColumnName();
X_WS_WebServiceFieldInput inputField = new X_WS_WebServiceFieldInput(getCtx(), rs, null);
if(inputField.isIdentifier())
m_keyColumns.add(colName);
m_inputFieldMap.put(colName,inputField );
} }
if(inputField.isIdentifier())
m_keyColumns.add(colName);
m_inputFieldMap.put(colName,inputField );
} }
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
} }
public X_WS_WebServiceFieldInput getFieldInput(String colName){ public X_WS_WebServiceFieldInput getFieldInput(String colName){

View File

@ -14,8 +14,6 @@
package org.idempiere.webservices; package org.idempiere.webservices;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -40,6 +38,7 @@ import org.compiere.model.MWebService;
import org.compiere.model.MWebServiceType; import org.compiere.model.MWebServiceType;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.model.X_WS_WebServiceMethod; import org.compiere.model.X_WS_WebServiceMethod;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -220,28 +219,13 @@ public class AbstractService {
if (m_webservicemethod == null || !m_webservicemethod.isActive()) if (m_webservicemethod == null || !m_webservicemethod.isActive())
return "Method " + methodValue + " not registered"; return "Method " + methodValue + " not registered";
MWebServiceType m_webservicetype = null; MWebServiceType m_webservicetype = new Query(m_cs.getCtx(), MWebServiceType.Table_Name,
final String sql = "SELECT * FROM WS_WebServiceType " + "WHERE AD_Client_ID=? " + "AND WS_WebService_ID=? " "AD_Client_ID IN (0,?) AND WS_WebService_ID=? AND WS_WebServiceMethod_ID=? AND Value=?",
+ "AND WS_WebServiceMethod_ID=? " + "AND Value=? " + "AND IsActive='Y'"; null)
PreparedStatement pstmt = null; .setOnlyActiveRecords(true)
ResultSet rs = null; .setParameters(m_cs.getAD_Client_ID(), m_webservice.getWS_WebService_ID(), m_webservicemethod.getWS_WebServiceMethod_ID(), serviceTypeValue)
try { .setOrderBy("AD_Client_ID DESC") // IDEMPIERE-3394 give precedence to tenant defined if there are system+tenant
pstmt = DB.prepareStatement(sql, null); .first();
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.getCtx(), rs, null);
} catch (Exception e) {
throw new IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName(
"authenticate"));
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (m_webservicetype == null) if (m_webservicetype == null)
return "Service type " + serviceTypeValue + " not configured"; return "Service type " + serviceTypeValue + " not configured";