IDEMPIERE-460 Integrate and migrate 3e services. 1) Fixed process management for compositeService and runProcess. 2) Added UUID support for _ID column. This allow portable hard coding for non official id web service configuration. 3) Added field and param lookup support for more places. 4) Clean up some old code.
This commit is contained in:
parent
67972e1d06
commit
284104f96f
|
@ -103,13 +103,17 @@ public class CompositeServiceImpl extends AbstractService implements CompositeSe
|
||||||
if (operationArr.length > 0) {
|
if (operationArr.length > 0) {
|
||||||
CompositeResponse compResp = resps.addNewCompositeResponse();
|
CompositeResponse compResp = resps.addNewCompositeResponse();
|
||||||
ArrayList<StandardResponse> respAggregator = new ArrayList<StandardResponse>();
|
ArrayList<StandardResponse> respAggregator = new ArrayList<StandardResponse>();
|
||||||
|
try {
|
||||||
boolean isSuccess = performOperations(trx, operationArr, modelADService, compResp, respAggregator, reqlogin);
|
boolean isSuccess = performOperations(trx, operationArr, modelADService, compResp, respAggregator, reqlogin);
|
||||||
|
|
||||||
// Committing after each operation set
|
// Committing after each operation set
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
commitTrx(trx, compResp, respAggregator, "Cannot commit at end of process", false);
|
commitTrx(trx, compResp, respAggregator, "Cannot commit at end of process", false);
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
rollbackAndSetError(trx, compResp, respAggregator, e.getLocalizedMessage());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -11,8 +11,17 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.idempiere.adinterface;
|
package org.idempiere.adinterface;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.Lookup;
|
import org.compiere.model.Lookup;
|
||||||
|
import org.compiere.model.MLookup;
|
||||||
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.KeyNamePair;
|
import org.compiere.util.KeyNamePair;
|
||||||
import org.compiere.util.ValueNamePair;
|
import org.compiere.util.ValueNamePair;
|
||||||
import org.idempiere.adInterface.x10.LookupValue;
|
import org.idempiere.adInterface.x10.LookupValue;
|
||||||
|
@ -64,4 +73,282 @@ public class ADLookup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate Access SQL for Search.
|
||||||
|
* The SQL returns the ID of the value entered
|
||||||
|
* Also sets m_tableName and m_keyColumnName
|
||||||
|
* @param text uppercase text for LIKE comparison
|
||||||
|
* @return sql or ""
|
||||||
|
* Example
|
||||||
|
* SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE x OR ...
|
||||||
|
*/
|
||||||
|
public static String getDirectAccessSQL (Lookup lookup, String text)
|
||||||
|
{
|
||||||
|
String m_columnName = lookup.getColumnName();
|
||||||
|
|
||||||
|
String m_tableName = null;
|
||||||
|
String m_keyColumnName = null;
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
if (m_columnName.indexOf(".") > 0) {
|
||||||
|
m_tableName = m_columnName.substring(0, m_columnName.indexOf("."));
|
||||||
|
m_keyColumnName = m_columnName.substring(m_columnName.indexOf(".")+1);
|
||||||
|
} else {
|
||||||
|
m_tableName = m_columnName.substring(0, m_columnName.length()-3);
|
||||||
|
m_keyColumnName = m_columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUUID(text))
|
||||||
|
{
|
||||||
|
sql.append("SELECT ").append(m_keyColumnName).append(" FROM ").append(m_tableName)
|
||||||
|
.append(" WHERE ").append(m_tableName).append("_UU=").append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("M_Product_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT M_Product_ID FROM M_Product WHERE (UPPER(Value) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text))
|
||||||
|
.append(" OR UPPER(Name) LIKE ").append(DB.TO_STRING(text))
|
||||||
|
.append(" OR UPC LIKE ").append(DB.TO_STRING(text)).append(")");
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("C_BPartner_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT C_BPartner_ID FROM C_BPartner WHERE (UPPER(Value) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text))
|
||||||
|
.append(" OR UPPER(Name) LIKE ").append(DB.TO_STRING(text)).append(")");
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("C_Order_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT C_Order_ID FROM C_Order WHERE UPPER(DocumentNo) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("C_Invoice_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT C_Invoice_ID FROM C_Invoice WHERE UPPER(DocumentNo) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("M_InOut_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT M_InOut_ID FROM M_InOut WHERE UPPER(DocumentNo) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("C_Payment_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("GL_JournalBatch_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT GL_JournalBatch_ID FROM GL_JournalBatch WHERE UPPER(DocumentNo) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
else if (m_columnName.equals("SalesRep_ID"))
|
||||||
|
{
|
||||||
|
sql.append("SELECT AD_User_ID FROM AD_User WHERE UPPER(Name) LIKE ")
|
||||||
|
.append(DB.TO_STRING(text));
|
||||||
|
|
||||||
|
m_tableName = "AD_User";
|
||||||
|
m_keyColumnName = "AD_User_ID";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Predefined
|
||||||
|
|
||||||
|
if (sql.length() > 0)
|
||||||
|
{
|
||||||
|
String wc = getWhereClause(lookup);
|
||||||
|
|
||||||
|
if (wc != null && wc.length() > 0)
|
||||||
|
sql.append(" AND ").append(wc);
|
||||||
|
|
||||||
|
sql.append(" AND IsActive='Y'");
|
||||||
|
// ***
|
||||||
|
|
||||||
|
if (log.isLoggable(Level.FINEST))
|
||||||
|
log.finest(m_columnName + " (predefined) " + sql.toString());
|
||||||
|
|
||||||
|
return MRole.getDefault().addAccessSQL(sql.toString(),
|
||||||
|
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it is a Table Reference
|
||||||
|
|
||||||
|
if (lookup != null && lookup instanceof MLookup)
|
||||||
|
{
|
||||||
|
int AD_Reference_ID = ((MLookup)lookup).getAD_Reference_Value_ID();
|
||||||
|
|
||||||
|
if (AD_Reference_ID != 0)
|
||||||
|
{
|
||||||
|
boolean isValueDisplayed = false;
|
||||||
|
String query = "SELECT kc.ColumnName, dc.ColumnName, t.TableName, rt.IsValueDisplayed "
|
||||||
|
+ "FROM AD_Ref_Table rt"
|
||||||
|
+ " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)"
|
||||||
|
+ " INNER JOIN AD_Column dc ON (rt.AD_Display=dc.AD_Column_ID)"
|
||||||
|
+ " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) "
|
||||||
|
+ "WHERE rt.AD_Reference_ID=?";
|
||||||
|
|
||||||
|
String displayColumnName = null;
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt = DB.prepareStatement(query, null);
|
||||||
|
pstmt.setInt(1, AD_Reference_ID);
|
||||||
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next())
|
||||||
|
{
|
||||||
|
m_keyColumnName = rs.getString(1);
|
||||||
|
displayColumnName = rs.getString(2);
|
||||||
|
m_tableName = rs.getString(3);
|
||||||
|
String t = rs.getString(4);
|
||||||
|
isValueDisplayed = "Y".equalsIgnoreCase(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, query, e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (displayColumnName != null)
|
||||||
|
{
|
||||||
|
sql = new StringBuffer();
|
||||||
|
sql.append("SELECT ").append(m_keyColumnName)
|
||||||
|
.append(" FROM ").append(m_tableName)
|
||||||
|
.append(" WHERE (UPPER(").append(displayColumnName)
|
||||||
|
.append(") LIKE ").append(DB.TO_STRING(text));
|
||||||
|
if (isValueDisplayed)
|
||||||
|
{
|
||||||
|
sql.append(" OR UPPER(").append("Value")
|
||||||
|
.append(") LIKE ").append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
sql.append(")");
|
||||||
|
sql.append(" AND IsActive='Y'");
|
||||||
|
|
||||||
|
String wc = getWhereClause(lookup);
|
||||||
|
|
||||||
|
if (wc != null && wc.length() > 0)
|
||||||
|
sql.append(" AND ").append(wc);
|
||||||
|
|
||||||
|
// ***
|
||||||
|
|
||||||
|
if (log.isLoggable(Level.FINEST))
|
||||||
|
log.finest(m_columnName + " (Table) " + sql.toString());
|
||||||
|
|
||||||
|
return MRole.getDefault().addAccessSQL(sql.toString(),
|
||||||
|
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||||
|
}
|
||||||
|
} // Table Reference
|
||||||
|
} // MLookup
|
||||||
|
|
||||||
|
/** Check Well Known Columns of Table - assumes TableDir **/
|
||||||
|
|
||||||
|
String query = "SELECT t.TableName, c.ColumnName "
|
||||||
|
+ "FROM AD_Column c "
|
||||||
|
+ " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID AND t.IsView='N') "
|
||||||
|
+ "WHERE (c.ColumnName IN ('DocumentNo', 'Value', 'Name') OR c.IsIdentifier='Y')"
|
||||||
|
+ " AND c.AD_Reference_ID IN (10,14)"
|
||||||
|
+ " AND EXISTS (SELECT * FROM AD_Column cc WHERE cc.AD_Table_ID=t.AD_Table_ID"
|
||||||
|
+ " AND cc.IsKey='Y' AND cc.ColumnName=?)";
|
||||||
|
|
||||||
|
sql = new StringBuffer();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt = DB.prepareStatement(query, null);
|
||||||
|
pstmt.setString(1, m_keyColumnName);
|
||||||
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
if (sql.length() != 0)
|
||||||
|
sql.append(" OR ");
|
||||||
|
|
||||||
|
m_tableName = rs.getString(1);
|
||||||
|
sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException ex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, query, ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (sql.length() == 0)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, m_columnName + " (TableDir) - no standard/identifier columns");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
//
|
||||||
|
StringBuffer retValue = new StringBuffer ("SELECT ")
|
||||||
|
.append(m_columnName).append(" FROM ").append(m_tableName)
|
||||||
|
.append(" WHERE ").append(sql)
|
||||||
|
.append(" AND IsActive='Y'");
|
||||||
|
|
||||||
|
String wc = getWhereClause(lookup);
|
||||||
|
|
||||||
|
if (wc != null && wc.length() > 0)
|
||||||
|
retValue.append(" AND ").append(wc);
|
||||||
|
// ***
|
||||||
|
if (log.isLoggable(Level.FINEST))
|
||||||
|
log.finest(m_columnName + " (TableDir) " + sql.toString());
|
||||||
|
return MRole.getDefault().addAccessSQL(retValue.toString(),
|
||||||
|
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getWhereClause(Lookup lookup)
|
||||||
|
{
|
||||||
|
String whereClause = "";
|
||||||
|
|
||||||
|
if (lookup == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (lookup.getZoomQuery() != null)
|
||||||
|
whereClause = lookup.getZoomQuery().getWhereClause();
|
||||||
|
|
||||||
|
String validation = lookup.getValidation();
|
||||||
|
|
||||||
|
if (validation == null)
|
||||||
|
validation = "";
|
||||||
|
|
||||||
|
if (whereClause.length() == 0)
|
||||||
|
whereClause = validation;
|
||||||
|
else if (validation.length() > 0)
|
||||||
|
whereClause += " AND " + validation;
|
||||||
|
|
||||||
|
if (whereClause.indexOf('@') != -1)
|
||||||
|
{
|
||||||
|
String validated = Env.parseContext(Env.getCtx(), lookup.getWindowNo(), whereClause, false);
|
||||||
|
|
||||||
|
if (validated.length() == 0)
|
||||||
|
log.severe(lookup.getColumnName() + " - Cannot Parse=" + whereClause);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (log.isLoggable(Level.FINE))
|
||||||
|
log.fine(lookup.getColumnName() + " - Parsed: " + validated);
|
||||||
|
return validated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return whereClause;
|
||||||
|
} // getWhereClause
|
||||||
|
|
||||||
|
private final static String UUID_REGEX="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value
|
||||||
|
* @return true if value is a uuid identifier
|
||||||
|
*/
|
||||||
|
public static boolean isUUID(String value)
|
||||||
|
{
|
||||||
|
return value == null ? false : value.matches(UUID_REGEX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ import javax.xml.ws.WebServiceContext;
|
||||||
import org.apache.xmlbeans.StringEnumAbstractBase.Table;
|
import org.apache.xmlbeans.StringEnumAbstractBase.Table;
|
||||||
import org.compiere.model.Lookup;
|
import org.compiere.model.Lookup;
|
||||||
import org.compiere.model.MColumn;
|
import org.compiere.model.MColumn;
|
||||||
import org.compiere.model.MLookup;
|
|
||||||
import org.compiere.model.MLookupFactory;
|
import org.compiere.model.MLookupFactory;
|
||||||
import org.compiere.model.MRefTable;
|
import org.compiere.model.MRefTable;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
@ -60,6 +59,7 @@ import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.Util;
|
||||||
import org.compiere.util.ValueNamePair;
|
import org.compiere.util.ValueNamePair;
|
||||||
import org.idempiere.adInterface.x10.ADLoginRequest;
|
import org.idempiere.adInterface.x10.ADLoginRequest;
|
||||||
import org.idempiere.adInterface.x10.DataField;
|
import org.idempiere.adInterface.x10.DataField;
|
||||||
|
@ -339,6 +339,25 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
return -1;
|
return -1;
|
||||||
if (string.equals(io.toString()))
|
if (string.equals(io.toString()))
|
||||||
return i;
|
return i;
|
||||||
|
if (parameterName.endsWith("_ID") && ADLookup.isUUID(string)) {
|
||||||
|
String tableName = parameterName.substring(0, parameterName.length()-3);
|
||||||
|
StringBuilder sql = new StringBuilder("SELECT ");
|
||||||
|
sql.append(parameterName).append(" FROM ").append(tableName)
|
||||||
|
.append(" WHERE ").append(tableName).append("_UU=").append(DB.TO_STRING(string));
|
||||||
|
return DB.getSQLValue(null, sql.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> requestCtx = getRequestCtx();
|
||||||
|
if (requestCtx != null && string.charAt(0) == '@') {
|
||||||
|
Object value = parseVatriable(getCompiereService(), requestCtx, parameterName, string);
|
||||||
|
if (value != null && value instanceof Number) {
|
||||||
|
return ((Number)value).intValue();
|
||||||
|
} else if (value != null ){
|
||||||
|
string = value.toString();
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return Integer.parseInt(string);
|
return Integer.parseInt(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +410,10 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
reqprocess.setADMenuID(modelRunProcess.getADMenuID());
|
reqprocess.setADMenuID(modelRunProcess.getADMenuID());
|
||||||
reqprocess.setADRecordID(modelRunProcess.getADRecordID());
|
reqprocess.setADRecordID(modelRunProcess.getADRecordID());
|
||||||
reqprocess.setDocAction(modelRunProcess.getDocAction());
|
reqprocess.setDocAction(modelRunProcess.getDocAction());
|
||||||
return Process.runProcess(getCompiereService(), docprocess);
|
RunProcessResponseDocument response = Process.runProcess(getCompiereService(), docprocess, getRequestCtx(), localTrxName);
|
||||||
|
Map<String, Object> requestCtx = getRequestCtx();
|
||||||
|
requestCtx.put(serviceType+"_Summary", response.getRunProcessResponse().getSummary());
|
||||||
|
return response;
|
||||||
} finally {
|
} finally {
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
|
@ -620,6 +642,9 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
public StandardResponseDocument deleteData(ModelCRUDRequestDocument req) {
|
public StandardResponseDocument deleteData(ModelCRUDRequestDocument req) {
|
||||||
boolean connected = getCompiereService().isConnected();
|
boolean connected = getCompiereService().isConnected();
|
||||||
|
|
||||||
|
Trx trx = null;
|
||||||
|
boolean manageTrx = this.manageTrx;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().connect();
|
getCompiereService().connect();
|
||||||
|
@ -655,7 +680,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
|
|
||||||
// start a trx
|
// start a trx
|
||||||
String trxName = localTrxName;
|
String trxName = localTrxName;
|
||||||
Trx trx = null;
|
|
||||||
if (trxName == null) {
|
if (trxName == null) {
|
||||||
trxName = Trx.createTrxName("ws_modelCreateData");
|
trxName = Trx.createTrxName("ws_modelCreateData");
|
||||||
manageTrx = true;
|
manageTrx = true;
|
||||||
|
@ -680,11 +705,11 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after delete record " + recordID + " in "
|
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after delete record " + recordID + " in "
|
||||||
+ tableName);
|
+ tableName);
|
||||||
|
|
||||||
if (manageTrx)
|
|
||||||
trx.close();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (manageTrx && trx != null)
|
||||||
|
trx.close();
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
}
|
}
|
||||||
|
@ -701,6 +726,9 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
|
|
||||||
boolean connected = getCompiereService().isConnected();
|
boolean connected = getCompiereService().isConnected();
|
||||||
|
|
||||||
|
Trx trx = null;
|
||||||
|
boolean manageTrx = this.manageTrx;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().connect();
|
getCompiereService().connect();
|
||||||
|
@ -734,7 +762,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
|
|
||||||
// start a trx
|
// start a trx
|
||||||
String trxName = localTrxName;
|
String trxName = localTrxName;
|
||||||
Trx trx = null;
|
|
||||||
if(trxName==null){
|
if(trxName==null){
|
||||||
trxName = Trx.createTrxName("ws_modelCreateData");
|
trxName = Trx.createTrxName("ws_modelCreateData");
|
||||||
manageTrx = true;
|
manageTrx = true;
|
||||||
|
@ -795,13 +823,13 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
if (manageTrx && !trx.commit())
|
if (manageTrx && !trx.commit())
|
||||||
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
|
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
|
||||||
|
|
||||||
if (manageTrx)
|
|
||||||
trx.close();
|
|
||||||
|
|
||||||
setOuputFields(resp, m_webservicetype,po,poinfo);
|
setOuputFields(resp, m_webservicetype,po,poinfo);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (manageTrx && trx != null)
|
||||||
|
trx.close();
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
|
|
||||||
|
@ -811,6 +839,9 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
public StandardResponseDocument createUpdateData(ModelCRUDRequestDocument req) {
|
public StandardResponseDocument createUpdateData(ModelCRUDRequestDocument req) {
|
||||||
boolean connected = getCompiereService().isConnected();
|
boolean connected = getCompiereService().isConnected();
|
||||||
|
|
||||||
|
Trx trx = null;
|
||||||
|
boolean manageTrx = this.manageTrx;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().connect();
|
getCompiereService().connect();
|
||||||
|
@ -844,7 +875,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
|
|
||||||
// start a trx
|
// start a trx
|
||||||
String trxName = localTrxName;
|
String trxName = localTrxName;
|
||||||
Trx trx = null;
|
|
||||||
if (trxName == null) {
|
if (trxName == null) {
|
||||||
trxName = Trx.createTrxName("ws_modelCreateData");
|
trxName = Trx.createTrxName("ws_modelCreateData");
|
||||||
manageTrx = true;
|
manageTrx = true;
|
||||||
|
@ -999,13 +1030,13 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in "
|
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in "
|
||||||
+ tableName);
|
+ tableName);
|
||||||
|
|
||||||
if (manageTrx)
|
|
||||||
trx.close();
|
|
||||||
|
|
||||||
setOuputFields(resp, m_webservicetype, po, poinfo);
|
setOuputFields(resp, m_webservicetype, po, poinfo);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (manageTrx && trx != null)
|
||||||
|
trx.close();
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
}
|
}
|
||||||
|
@ -1018,7 +1049,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
Object value = null;
|
Object value = null;
|
||||||
String strValue = field.getVal();
|
String strValue = field.getVal();
|
||||||
String lookupValue = field.getLval();
|
String lookupValue = field.getLval();
|
||||||
if (lookupValue != null && !"".equals(lookupValue)) {
|
if (!Util.isEmpty(lookupValue)) {
|
||||||
Lookup lookup = null;
|
Lookup lookup = null;
|
||||||
|
|
||||||
if(fieldInput.getAD_Reference_ID() > 0 && fieldInput.getAD_Reference_Value_ID()>0)
|
if(fieldInput.getAD_Reference_ID() > 0 && fieldInput.getAD_Reference_Value_ID()>0)
|
||||||
|
@ -1040,7 +1071,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
"LookupResolutionFailed"));
|
"LookupResolutionFailed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String sql = getDirectAccessSQL(lookup, lookupValue.toUpperCase());
|
String sql = ADLookup.getDirectAccessSQL(lookup, lookupValue.toUpperCase());
|
||||||
int id = DB.getSQLValue(localTrxName, sql);
|
int id = DB.getSQLValue(localTrxName, sql);
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
value = id;
|
value = id;
|
||||||
|
@ -1054,44 +1085,12 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
} else {
|
} else {
|
||||||
Map<String, Object> requestCtx = getRequestCtx();
|
Map<String, Object> requestCtx = getRequestCtx();
|
||||||
if (requestCtx != null && strValue.charAt(0) == '@') {
|
if (requestCtx != null && strValue.charAt(0) == '@') {
|
||||||
String varName = strValue.substring(1);
|
value = parseVatriable(getCompiereService(), requestCtx, field.getColumn(), strValue);
|
||||||
if (varName.charAt(0) == '#') {
|
|
||||||
varName = varName.substring(1);
|
|
||||||
strValue = m_cs.getCtx().getProperty(varName);
|
|
||||||
} else {
|
|
||||||
int indDot = varName.indexOf(".");
|
|
||||||
if (indDot == -1) {
|
|
||||||
// If there is no table name, then it should be
|
|
||||||
// premitive data type
|
|
||||||
value = requestCtx.get(varName);
|
|
||||||
} else {
|
|
||||||
String tblName = varName.substring(0, indDot);
|
|
||||||
String colName = varName.substring(indDot + 1);
|
|
||||||
if (colName.indexOf(".") >= 0) {
|
|
||||||
throw new IdempiereServiceFault(field.getVal() + " contains un supported multi level object resolution",
|
|
||||||
new QName("resolveCtxVariable"));
|
|
||||||
}
|
|
||||||
Object obj = requestCtx.get(tblName);
|
|
||||||
if (obj == null || !(obj instanceof PO)) {
|
|
||||||
throw new IdempiereServiceFault(" input column " + field.getColumn() + " can not found object of " + tblName
|
|
||||||
+ ". Request variable " + field.getVal() + " can not resolved", new QName("resolveCtxVariable"));
|
|
||||||
}
|
|
||||||
|
|
||||||
PO refPO = (PO) obj;
|
|
||||||
value = refPO.get_Value(colName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
throw new IdempiereServiceFault(
|
|
||||||
" input column " + field.getColumn() + " can not be resolved for value " + strValue, new QName(
|
|
||||||
"resolveCtxVariable"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
||||||
value = convertToObj(strValue, columnClass, field.getColumn());
|
value = convertToObj(strValue, columnClass, field.getColumn());
|
||||||
|
} else if (value instanceof String && !columnClass.equals(String.class)) {
|
||||||
|
value = convertToObj(value.toString(), columnClass, field.getColumn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!po.set_ValueOfColumnReturningBoolean(field.getColumn(), value)) {
|
if (!po.set_ValueOfColumnReturningBoolean(field.getColumn(), value)) {
|
||||||
|
@ -1105,6 +1104,38 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
Env.setContext(Env.getCtx(), 0, field.getColumn(), value==null ? null : value.toString());
|
Env.setContext(Env.getCtx(), 0, field.getColumn(), value==null ? null : value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object parseVatriable(CompiereService cs, Map<String, Object> requestCtx, String name,
|
||||||
|
String strValue) {
|
||||||
|
String varName = strValue.substring(1);
|
||||||
|
if (varName.charAt(0) == '#') {
|
||||||
|
varName = varName.substring(1);
|
||||||
|
return cs.getCtx().getProperty(varName);
|
||||||
|
} else {
|
||||||
|
int indDot = varName.indexOf(".");
|
||||||
|
if (indDot == -1) {
|
||||||
|
// If there is no table name, then it should be
|
||||||
|
// premitive data type
|
||||||
|
return requestCtx.get(varName);
|
||||||
|
} else {
|
||||||
|
String tblName = varName.substring(0, indDot);
|
||||||
|
String colName = varName.substring(indDot + 1);
|
||||||
|
if (colName.indexOf(".") >= 0) {
|
||||||
|
throw new IdempiereServiceFault(strValue + " contains un supported multi level object resolution",
|
||||||
|
new QName("resolveCtxVariable"));
|
||||||
|
}
|
||||||
|
Object obj = requestCtx.get(tblName);
|
||||||
|
if (obj == null || !(obj instanceof PO)) {
|
||||||
|
throw new IdempiereServiceFault(" input column " + name + " can not found object of " + tblName
|
||||||
|
+ ". Request variable " + strValue + " can not resolved", new QName("resolveCtxVariable"));
|
||||||
|
}
|
||||||
|
|
||||||
|
PO refPO = (PO) obj;
|
||||||
|
return refPO.get_Value(colName);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public StandardResponseDocument scanFields(DataField[] fields,MWebServiceType m_webservicetype,PO po,POInfo poinfo,Trx trx,StandardResponse resp, StandardResponseDocument ret){
|
public StandardResponseDocument scanFields(DataField[] fields,MWebServiceType m_webservicetype,PO po,POInfo poinfo,Trx trx,StandardResponse resp, StandardResponseDocument ret){
|
||||||
Map<String,Object> requestCtx = getRequestCtx();
|
Map<String,Object> requestCtx = getRequestCtx();
|
||||||
|
|
||||||
|
@ -1159,6 +1190,9 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
public StandardResponseDocument updateData(ModelCRUDRequestDocument req){
|
public StandardResponseDocument updateData(ModelCRUDRequestDocument req){
|
||||||
boolean connected = getCompiereService().isConnected();
|
boolean connected = getCompiereService().isConnected();
|
||||||
|
|
||||||
|
Trx trx = null;
|
||||||
|
boolean manageTrx = this.manageTrx;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().connect();
|
getCompiereService().connect();
|
||||||
|
@ -1195,7 +1229,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
|
|
||||||
// start a trx
|
// start a trx
|
||||||
String trxName = localTrxName;
|
String trxName = localTrxName;
|
||||||
Trx trx = null;
|
|
||||||
if(trxName==null){
|
if(trxName==null){
|
||||||
trxName = Trx.createTrxName("ws_modelCreateData");
|
trxName = Trx.createTrxName("ws_modelCreateData");
|
||||||
manageTrx = true;
|
manageTrx = true;
|
||||||
|
@ -1234,13 +1268,13 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in "
|
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in "
|
||||||
+ tableName);
|
+ tableName);
|
||||||
|
|
||||||
if (manageTrx)
|
|
||||||
trx.close();
|
|
||||||
|
|
||||||
setOuputFields(resp, m_webservicetype, po, poinfo);
|
setOuputFields(resp, m_webservicetype, po, poinfo);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (manageTrx && trx != null)
|
||||||
|
trx.close();
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
}
|
}
|
||||||
|
@ -1407,7 +1441,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
ResultSet rsquery = null;
|
ResultSet rsquery = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmtquery = DB.prepareStatement (sqlquery, null);
|
pstmtquery = DB.prepareStatement (sqlquery, localTrxName);
|
||||||
int p = 1;
|
int p = 1;
|
||||||
if (modelCRUD.getDataRow() != null)
|
if (modelCRUD.getDataRow() != null)
|
||||||
{
|
{
|
||||||
|
@ -1415,7 +1449,43 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
int idx = poinfo.getColumnIndex(field.getColumn());
|
int idx = poinfo.getColumnIndex(field.getColumn());
|
||||||
Class<?> c = poinfo.getColumnClass(idx);
|
Class<?> c = poinfo.getColumnClass(idx);
|
||||||
if (c == Integer.class)
|
if (c == Integer.class)
|
||||||
pstmtquery.setInt(p++, Integer.valueOf(field.getVal()));
|
{
|
||||||
|
int value = 0;
|
||||||
|
if (Util.isEmpty(field.getVal()) && !Util.isEmpty(field.getLval()))
|
||||||
|
{
|
||||||
|
Lookup lookup = null;
|
||||||
|
int idxcol = poinfo.getColumnIndex(field.getColumn());
|
||||||
|
X_WS_WebServiceFieldInput fieldInput = m_webservicetype.getFieldInput(field.getColumn());
|
||||||
|
if(fieldInput.getAD_Reference_ID() > 0 && fieldInput.getAD_Reference_Value_ID()>0)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
lookup = MLookupFactory.get(m_cs.getCtx(),0,poinfo.getAD_Column_ID(poinfo.getColumnName(idxcol)),fieldInput.getAD_Reference_ID(),Env.getLanguage(m_cs.getCtx()),poinfo.getColumnName(idxcol),fieldInput.getAD_Reference_Value_ID(),false,null);
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new IdempiereServiceFault("Exception in resolving overridden lookup ", new QName(
|
||||||
|
"LookupResolutionFailed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lookup = poinfo.getColumnLookup(idxcol);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lookup == null) {
|
||||||
|
throw new IdempiereServiceFault(field.getColumn() + " is not lookup column. Pass Value in val element ", new QName(
|
||||||
|
"LookupResolutionFailed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = ADLookup.getDirectAccessSQL(lookup, field.getLval().toUpperCase());
|
||||||
|
int id = DB.getSQLValue(localTrxName, sql);
|
||||||
|
if (id > 0)
|
||||||
|
value = id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = Integer.valueOf(field.getVal());
|
||||||
|
}
|
||||||
|
pstmtquery.setInt(p++, value);
|
||||||
|
}
|
||||||
else if (c == Timestamp.class)
|
else if (c == Timestamp.class)
|
||||||
pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal()));
|
pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal()));
|
||||||
else if (c == Boolean.class || c == String.class)
|
else if (c == Boolean.class || c == String.class)
|
||||||
|
@ -1440,7 +1510,7 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// ignore this exception
|
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -1460,271 +1530,4 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
|
||||||
getCompiereService().disconnect();
|
getCompiereService().disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Access SQL for Search.
|
|
||||||
* The SQL returns the ID of the value entered
|
|
||||||
* Also sets m_tableName and m_keyColumnName
|
|
||||||
* @param text uppercase text for LIKE comparison
|
|
||||||
* @return sql or ""
|
|
||||||
* Example
|
|
||||||
* SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE x OR ...
|
|
||||||
*/
|
|
||||||
private String getDirectAccessSQL (Lookup lookup, String text)
|
|
||||||
{
|
|
||||||
String m_columnName = lookup.getColumnName();
|
|
||||||
|
|
||||||
String m_tableName = null;
|
|
||||||
String m_keyColumnName = null;
|
|
||||||
StringBuffer sql = new StringBuffer();
|
|
||||||
if (m_columnName.indexOf(".") > 0) {
|
|
||||||
m_tableName = m_columnName.substring(0, m_columnName.indexOf("."));
|
|
||||||
m_keyColumnName = m_columnName.substring(m_columnName.indexOf(".")+1);
|
|
||||||
} else {
|
|
||||||
m_tableName = m_columnName.substring(0, m_columnName.length()-3);
|
|
||||||
m_keyColumnName = m_columnName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_columnName.equals("M_Product_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT M_Product_ID FROM M_Product WHERE (UPPER(Value) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text))
|
|
||||||
.append(" OR UPPER(Name) LIKE ").append(DB.TO_STRING(text))
|
|
||||||
.append(" OR UPC LIKE ").append(DB.TO_STRING(text)).append(")");
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("C_BPartner_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT C_BPartner_ID FROM C_BPartner WHERE (UPPER(Value) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text))
|
|
||||||
.append(" OR UPPER(Name) LIKE ").append(DB.TO_STRING(text)).append(")");
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("C_Order_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT C_Order_ID FROM C_Order WHERE UPPER(DocumentNo) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("C_Invoice_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT C_Invoice_ID FROM C_Invoice WHERE UPPER(DocumentNo) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("M_InOut_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT M_InOut_ID FROM M_InOut WHERE UPPER(DocumentNo) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("C_Payment_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("GL_JournalBatch_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT GL_JournalBatch_ID FROM GL_JournalBatch WHERE UPPER(DocumentNo) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
else if (m_columnName.equals("SalesRep_ID"))
|
|
||||||
{
|
|
||||||
sql.append("SELECT AD_User_ID FROM AD_User WHERE UPPER(Name) LIKE ")
|
|
||||||
.append(DB.TO_STRING(text));
|
|
||||||
|
|
||||||
m_tableName = "AD_User";
|
|
||||||
m_keyColumnName = "AD_User_ID";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Predefined
|
|
||||||
|
|
||||||
if (sql.length() > 0)
|
|
||||||
{
|
|
||||||
String wc = getWhereClause(lookup);
|
|
||||||
|
|
||||||
if (wc != null && wc.length() > 0)
|
|
||||||
sql.append(" AND ").append(wc);
|
|
||||||
|
|
||||||
sql.append(" AND IsActive='Y'");
|
|
||||||
// ***
|
|
||||||
|
|
||||||
if (log.isLoggable(Level.FINEST))
|
|
||||||
log.finest(m_columnName + " (predefined) " + sql.toString());
|
|
||||||
|
|
||||||
return MRole.getDefault().addAccessSQL(sql.toString(),
|
|
||||||
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it is a Table Reference
|
|
||||||
|
|
||||||
if (lookup != null && lookup instanceof MLookup)
|
|
||||||
{
|
|
||||||
int AD_Reference_ID = ((MLookup)lookup).getAD_Reference_Value_ID();
|
|
||||||
|
|
||||||
if (AD_Reference_ID != 0)
|
|
||||||
{
|
|
||||||
boolean isValueDisplayed = false;
|
|
||||||
String query = "SELECT kc.ColumnName, dc.ColumnName, t.TableName, rt.IsValueDisplayed "
|
|
||||||
+ "FROM AD_Ref_Table rt"
|
|
||||||
+ " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)"
|
|
||||||
+ " INNER JOIN AD_Column dc ON (rt.AD_Display=dc.AD_Column_ID)"
|
|
||||||
+ " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) "
|
|
||||||
+ "WHERE rt.AD_Reference_ID=?";
|
|
||||||
|
|
||||||
String displayColumnName = null;
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(query, null);
|
|
||||||
pstmt.setInt(1, AD_Reference_ID);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
|
|
||||||
if (rs.next())
|
|
||||||
{
|
|
||||||
m_keyColumnName = rs.getString(1);
|
|
||||||
displayColumnName = rs.getString(2);
|
|
||||||
m_tableName = rs.getString(3);
|
|
||||||
String t = rs.getString(4);
|
|
||||||
isValueDisplayed = "Y".equalsIgnoreCase(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, query, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (displayColumnName != null)
|
|
||||||
{
|
|
||||||
sql = new StringBuffer();
|
|
||||||
sql.append("SELECT ").append(m_keyColumnName)
|
|
||||||
.append(" FROM ").append(m_tableName)
|
|
||||||
.append(" WHERE (UPPER(").append(displayColumnName)
|
|
||||||
.append(") LIKE ").append(DB.TO_STRING(text));
|
|
||||||
if (isValueDisplayed)
|
|
||||||
{
|
|
||||||
sql.append(" OR UPPER(").append("Value")
|
|
||||||
.append(") LIKE ").append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
sql.append(")");
|
|
||||||
sql.append(" AND IsActive='Y'");
|
|
||||||
|
|
||||||
String wc = getWhereClause(lookup);
|
|
||||||
|
|
||||||
if (wc != null && wc.length() > 0)
|
|
||||||
sql.append(" AND ").append(wc);
|
|
||||||
|
|
||||||
// ***
|
|
||||||
|
|
||||||
if (log.isLoggable(Level.FINEST))
|
|
||||||
log.finest(m_columnName + " (Table) " + sql.toString());
|
|
||||||
|
|
||||||
return MRole.getDefault().addAccessSQL(sql.toString(),
|
|
||||||
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
|
||||||
}
|
|
||||||
} // Table Reference
|
|
||||||
} // MLookup
|
|
||||||
|
|
||||||
/** Check Well Known Columns of Table - assumes TableDir **/
|
|
||||||
|
|
||||||
String query = "SELECT t.TableName, c.ColumnName "
|
|
||||||
+ "FROM AD_Column c "
|
|
||||||
+ " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID AND t.IsView='N') "
|
|
||||||
+ "WHERE (c.ColumnName IN ('DocumentNo', 'Value', 'Name') OR c.IsIdentifier='Y')"
|
|
||||||
+ " AND c.AD_Reference_ID IN (10,14)"
|
|
||||||
+ " AND EXISTS (SELECT * FROM AD_Column cc WHERE cc.AD_Table_ID=t.AD_Table_ID"
|
|
||||||
+ " AND cc.IsKey='Y' AND cc.ColumnName=?)";
|
|
||||||
|
|
||||||
sql = new StringBuffer();
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(query, null);
|
|
||||||
pstmt.setString(1, m_keyColumnName);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
if (sql.length() != 0)
|
|
||||||
sql.append(" OR ");
|
|
||||||
|
|
||||||
m_tableName = rs.getString(1);
|
|
||||||
sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, query, ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
if (sql.length() == 0)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, m_columnName + " (TableDir) - no standard/identifier columns");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
//
|
|
||||||
StringBuffer retValue = new StringBuffer ("SELECT ")
|
|
||||||
.append(m_columnName).append(" FROM ").append(m_tableName)
|
|
||||||
.append(" WHERE ").append(sql)
|
|
||||||
.append(" AND IsActive='Y'");
|
|
||||||
|
|
||||||
String wc = getWhereClause(lookup);
|
|
||||||
|
|
||||||
if (wc != null && wc.length() > 0)
|
|
||||||
retValue.append(" AND ").append(wc);
|
|
||||||
// ***
|
|
||||||
if (log.isLoggable(Level.FINEST))
|
|
||||||
log.finest(m_columnName + " (TableDir) " + sql.toString());
|
|
||||||
return MRole.getDefault().addAccessSQL(retValue.toString(),
|
|
||||||
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getWhereClause(Lookup lookup)
|
|
||||||
{
|
|
||||||
String whereClause = "";
|
|
||||||
|
|
||||||
if (lookup == null)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
if (lookup.getZoomQuery() != null)
|
|
||||||
whereClause = lookup.getZoomQuery().getWhereClause();
|
|
||||||
|
|
||||||
String validation = lookup.getValidation();
|
|
||||||
|
|
||||||
if (validation == null)
|
|
||||||
validation = "";
|
|
||||||
|
|
||||||
if (whereClause.length() == 0)
|
|
||||||
whereClause = validation;
|
|
||||||
else if (validation.length() > 0)
|
|
||||||
whereClause += " AND " + validation;
|
|
||||||
|
|
||||||
// log.finest("ZoomQuery=" + (lookup.getZoomQuery()==null ? "" : lookup.getZoomQuery().getWhereClause())
|
|
||||||
// + ", Validation=" + lookup.getValidation());
|
|
||||||
|
|
||||||
if (whereClause.indexOf('@') != -1)
|
|
||||||
{
|
|
||||||
String validated = Env.parseContext(Env.getCtx(), lookup.getWindowNo(), whereClause, false);
|
|
||||||
|
|
||||||
if (validated.length() == 0)
|
|
||||||
log.severe(lookup.getColumnName() + " - Cannot Parse=" + whereClause);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (log.isLoggable(Level.FINE))
|
|
||||||
log.fine(lookup.getColumnName() + " - Parsed: " + validated);
|
|
||||||
return validated;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return whereClause;
|
|
||||||
} // getWhereClause
|
|
||||||
}
|
}
|
|
@ -5,13 +5,18 @@ import java.io.CharArrayWriter;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import net.sf.compilo.report.ReportProcessor;
|
import net.sf.compilo.report.ReportProcessor;
|
||||||
import net.sf.jasperreports.engine.JasperPrint;
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
|
||||||
import org.compiere.model.Lookup;
|
import org.compiere.model.Lookup;
|
||||||
|
import org.compiere.model.MLookup;
|
||||||
|
import org.compiere.model.MLookupFactory;
|
||||||
import org.compiere.model.MPInstance;
|
import org.compiere.model.MPInstance;
|
||||||
import org.compiere.model.MPInstancePara;
|
import org.compiere.model.MPInstancePara;
|
||||||
import org.compiere.model.MPaySelectionCheck;
|
import org.compiere.model.MPaySelectionCheck;
|
||||||
|
@ -24,11 +29,15 @@ import org.compiere.model.PrintInfo;
|
||||||
import org.compiere.print.MPrintFormat;
|
import org.compiere.print.MPrintFormat;
|
||||||
import org.compiere.print.ReportEngine;
|
import org.compiere.print.ReportEngine;
|
||||||
import org.compiere.process.ProcessInfo;
|
import org.compiere.process.ProcessInfo;
|
||||||
|
import org.compiere.process.ProcessInfoParameter;
|
||||||
|
import org.compiere.process.ProcessInfoUtil;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.NamePair;
|
import org.compiere.util.NamePair;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.Util;
|
||||||
import org.compiere.wf.MWFProcess;
|
import org.compiere.wf.MWFProcess;
|
||||||
import org.compiere.wf.MWorkflow;
|
import org.compiere.wf.MWorkflow;
|
||||||
import org.idempiere.adInterface.x10.DataField;
|
import org.idempiere.adInterface.x10.DataField;
|
||||||
|
@ -43,6 +52,7 @@ import org.idempiere.adInterface.x10.RunProcess;
|
||||||
import org.idempiere.adInterface.x10.RunProcessDocument;
|
import org.idempiere.adInterface.x10.RunProcessDocument;
|
||||||
import org.idempiere.adInterface.x10.RunProcessResponse;
|
import org.idempiere.adInterface.x10.RunProcessResponse;
|
||||||
import org.idempiere.adInterface.x10.RunProcessResponseDocument;
|
import org.idempiere.adInterface.x10.RunProcessResponseDocument;
|
||||||
|
import org.idempiere.webservices.fault.IdempiereServiceFault;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ADEMPIERE/COMPIERE
|
* ADEMPIERE/COMPIERE
|
||||||
|
@ -149,13 +159,26 @@ public class Process {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Create Process Page
|
* Run process
|
||||||
* @param AD_Process_ID Process
|
* @param m_cs
|
||||||
* @return Page
|
* @param req
|
||||||
|
* @return {@link RunProcessResponseDocument}
|
||||||
*/
|
*/
|
||||||
public static RunProcessResponseDocument runProcess (CompiereService m_cs, RunProcessDocument req )
|
public static RunProcessResponseDocument runProcess (CompiereService m_cs, RunProcessDocument req )
|
||||||
|
{
|
||||||
|
return runProcess(m_cs, req, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Run process
|
||||||
|
* @param m_cs
|
||||||
|
* @param req
|
||||||
|
* @param requestCtx
|
||||||
|
* @param trxName
|
||||||
|
* @return {@link RunProcessResponseDocument}
|
||||||
|
*/
|
||||||
|
public static RunProcessResponseDocument runProcess (CompiereService m_cs, RunProcessDocument req, Map<String, Object> requestCtx, String trxName )
|
||||||
{
|
{
|
||||||
RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
|
RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
|
||||||
RunProcessResponse r= res.addNewRunProcessResponse();
|
RunProcessResponse r= res.addNewRunProcessResponse();
|
||||||
|
@ -163,19 +186,15 @@ public class Process {
|
||||||
RunProcess rp = req.getRunProcess();
|
RunProcess rp = req.getRunProcess();
|
||||||
int AD_Process_ID = rp.getADProcessID();
|
int AD_Process_ID = rp.getADProcessID();
|
||||||
int m_record_id = rp.getADRecordID();
|
int m_record_id = rp.getADRecordID();
|
||||||
//WebSessionCtx wsc = WebSessionCtx.get (request);
|
|
||||||
|
|
||||||
MProcess process = MProcess.get (m_cs.getCtx() , AD_Process_ID);
|
MProcess process = MProcess.get (m_cs.getCtx() , AD_Process_ID);
|
||||||
// need to check if Role can access
|
// need to check if Role can access
|
||||||
if (process == null)
|
if (process == null)
|
||||||
{
|
{
|
||||||
// WebDoc doc = WebDoc.createWindow("Process not found");
|
|
||||||
r.setError("Process not found");
|
r.setError("Process not found");
|
||||||
r.setIsError( true );
|
r.setIsError( true );
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
//process.getDescription()
|
|
||||||
//process.getHelp()
|
|
||||||
|
|
||||||
// Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
|
// Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
|
||||||
String docAction = rp.getDocAction();
|
String docAction = rp.getDocAction();
|
||||||
|
@ -205,16 +224,39 @@ public class Process {
|
||||||
MPInstance pInstance = null;
|
MPInstance pInstance = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pInstance = fillParameter (m_cs, rp.getParamValues(), process);
|
pInstance = fillParameter (m_cs, rp.getParamValues(), process, requestCtx);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//center.addElement(new p("B<EFBFBD><EFBFBD>d: " + ex.getMessage(), AlignType.LEFT).setClass("ProcesResultError"));
|
|
||||||
r.setError(ex.getMessage());
|
r.setError(ex.getMessage());
|
||||||
r.setIsError( true );
|
r.setIsError( true );
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataField[] fields = rp.getParamValues().getFieldArray();
|
||||||
|
for(DataField field : fields) {
|
||||||
|
if ("AD_Record_ID".equals(field.getColumn())) {
|
||||||
|
Object value = null;
|
||||||
|
String s = field.getVal();
|
||||||
|
if (requestCtx != null && !Util.isEmpty(s) && s.charAt(0) == '@') {
|
||||||
|
value = ModelADServiceImpl.parseVatriable(m_cs, requestCtx, field.getColumn(), s);
|
||||||
|
if (value != null) {
|
||||||
|
if (value instanceof Number) {
|
||||||
|
m_record_id = ((Number)value).intValue();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
m_record_id = Integer.parseInt(value.toString());
|
||||||
|
} catch (Exception e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!Util.isEmpty(s)) {
|
||||||
|
try {
|
||||||
|
m_record_id = Integer.parseInt(s);
|
||||||
|
} catch (Exception e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_record_id>0)
|
if (m_record_id>0)
|
||||||
{
|
{
|
||||||
pInstance.setRecord_ID( m_record_id);
|
pInstance.setRecord_ID( m_record_id);
|
||||||
|
@ -227,18 +269,29 @@ public class Process {
|
||||||
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
|
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
|
||||||
if (m_record_id >0)
|
if (m_record_id >0)
|
||||||
pi.setRecord_ID( m_record_id );
|
pi.setRecord_ID( m_record_id );
|
||||||
|
ProcessInfoParameter[] parameters = pi.getParameter();
|
||||||
|
if (parameters == null)
|
||||||
|
{
|
||||||
|
ProcessInfoUtil.setParameterFromDB(pi);
|
||||||
|
parameters = pi.getParameter();
|
||||||
|
}
|
||||||
|
for(DataField field : fields) {
|
||||||
|
if (isDataURI(field.getVal())) {
|
||||||
|
for(ProcessInfoParameter param : parameters) {
|
||||||
|
if (param.getParameterName().equals(field.getColumn())) {
|
||||||
|
String data = field.getVal().substring(field.getVal().indexOf(";base64,")+";base64,".length());
|
||||||
|
param.setParameter(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Info
|
|
||||||
//p p = new p();
|
|
||||||
//p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
|
|
||||||
//center.addElement(p);
|
|
||||||
boolean processOK = false;
|
boolean processOK = false;
|
||||||
|
|
||||||
boolean jasperreport = (process != null && process.getClassname()!=null && process.getClassname().indexOf( "net.sf.compilo.report.ReportStarter" ) >=0 );
|
boolean jasperreport = (process != null && process.getClassname()!=null && process.getClassname().indexOf( "net.sf.compilo.report.ReportStarter" ) >=0 );
|
||||||
|
|
||||||
if (jasperreport)
|
if (jasperreport)
|
||||||
{
|
{
|
||||||
//this.jasperReport( request, response, wsc.ctx, pi);
|
|
||||||
processOK = true;
|
processOK = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,28 +318,29 @@ public class Process {
|
||||||
r.setLogInfo(pi.getLogInfo(true) );
|
r.setLogInfo(pi.getLogInfo(true) );
|
||||||
r.setIsError( true );
|
r.setIsError( true );
|
||||||
return res;
|
return res;
|
||||||
//Wyj<EFBFBD>tek: pi.getLogInfo(true) pi.getLogInfo(true)
|
|
||||||
}
|
}
|
||||||
//started = wfProcess != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.isJavaProcess() && !jasperreport)
|
if (process.isJavaProcess() && !jasperreport)
|
||||||
{
|
{
|
||||||
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
|
Trx trx = trxName == null ? Trx.get(Trx.createTrxName("WebPrc"), true) : Trx.get(trxName, true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
processOK = process.processIt(pi, trx);
|
processOK = process.processIt(pi, trx, false);
|
||||||
|
if (trxName == null)
|
||||||
trx.commit();
|
trx.commit();
|
||||||
trx.close();
|
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (trxName == null)
|
||||||
trx.close();
|
trx.close();
|
||||||
}
|
}
|
||||||
if (!processOK || pi.isError())
|
if (!processOK || pi.isError())
|
||||||
{
|
{
|
||||||
// b<EFBFBD><EFBFBD>d: pi.getSummary()
|
|
||||||
r.setSummary(pi.getSummary());
|
r.setSummary(pi.getSummary());
|
||||||
r.setLogInfo(pi.getLogInfo(true));
|
r.setLogInfo(pi.getLogInfo(true));
|
||||||
r.setIsError( true );
|
r.setIsError( true );
|
||||||
|
@ -297,28 +351,20 @@ public class Process {
|
||||||
r.setSummary(pi.getSummary());
|
r.setSummary(pi.getSummary());
|
||||||
r.setLogInfo(pi.getLogInfo(true));
|
r.setLogInfo(pi.getLogInfo(true));
|
||||||
r.setIsError( false );
|
r.setIsError( false );
|
||||||
//return res;
|
|
||||||
// wynik - String summary = pi.getSummary();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report
|
// Report
|
||||||
if (/*processOK &&*/ (process.isReport() || jasperreport))//&& !m_jasperreport)
|
if ((process.isReport() || jasperreport))
|
||||||
{
|
{
|
||||||
r.setIsReport(true);
|
r.setIsReport(true);
|
||||||
//if (m_jasperreport)
|
|
||||||
//{
|
|
||||||
// center.addElement(new p("JASPER REPORT", AlignType.LEFT).setClass("Cerror"));
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
ReportEngine re=null;
|
ReportEngine re=null;
|
||||||
if (!jasperreport)
|
if (!jasperreport)
|
||||||
re = start(pi);
|
re = start(pi);
|
||||||
|
|
||||||
if (re == null && !jasperreport)
|
if (re == null && !jasperreport)
|
||||||
{
|
{
|
||||||
//b<EFBFBD><EFBFBD>d: "Nie uda<64>o si<73> uruchomi<6D> silnika raport<72>w (ReportEngine)",
|
;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -346,16 +392,13 @@ public class Process {
|
||||||
r.setReportFormat(file_type);
|
r.setReportFormat(file_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
//r.setReportFormat("xls");
|
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JasperPrint jp = getJasperReportPrint( m_cs.getCtx(), pi);
|
JasperPrint jp = getJasperReportPrint( m_cs.getCtx(), pi);
|
||||||
//file = File.createTempFile("WProcess", ".pdf");
|
|
||||||
ByteArrayOutputStream wr = new ByteArrayOutputStream();
|
ByteArrayOutputStream wr = new ByteArrayOutputStream();
|
||||||
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
|
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
|
||||||
//exportReportToPdfFile( jp, file.getAbsolutePath() );
|
|
||||||
file_type ="pdf";
|
file_type ="pdf";
|
||||||
r.setData(wr.toByteArray());
|
r.setData(wr.toByteArray());
|
||||||
r.setReportFormat(file_type);
|
r.setReportFormat(file_type);
|
||||||
|
@ -364,9 +407,6 @@ public class Process {
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
//pInstance.getAD_PInstance_ID()
|
|
||||||
//file.getAbsolutePath()
|
|
||||||
|
|
||||||
// Marker that Process is OK
|
// Marker that Process is OK
|
||||||
m_cs.getCtx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
|
m_cs.getCtx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
|
||||||
}
|
}
|
||||||
|
@ -376,7 +416,6 @@ public class Process {
|
||||||
r.setLogInfo(pi.getLogInfo(true) );
|
r.setLogInfo(pi.getLogInfo(true) );
|
||||||
r.setIsError( true );
|
r.setIsError( true );
|
||||||
return res;
|
return res;
|
||||||
//"Cannot create report:",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -389,20 +428,19 @@ public class Process {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
} // createProcessPage
|
} // createProcessPage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception
|
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process, Map<String, Object> requestCtx) throws Exception
|
||||||
{
|
{
|
||||||
MPInstance pInstance = new MPInstance (process, 0);
|
MPInstance pInstance = new MPInstance (process, 0);
|
||||||
|
|
||||||
DataField f[] = dr.getFieldArray();
|
DataField f[] = dr.getFieldArray();
|
||||||
HashMap<String,String> fmap = new HashMap<String,String>();
|
HashMap<String,DataField> fmap = new HashMap<String,DataField>();
|
||||||
for (int i=0; i<f.length; i++)
|
for (int i=0; i<f.length; i++)
|
||||||
fmap.put(f[i].getColumn(), f[i].getVal());
|
fmap.put(f[i].getColumn(), f[i]);
|
||||||
//
|
//
|
||||||
MPInstancePara[] iParams = pInstance.getParameters();
|
MPInstancePara[] iParams = pInstance.getParameters();
|
||||||
for (int pi = 0; pi < iParams.length; pi++)
|
for (int pi = 0; pi < iParams.length; pi++)
|
||||||
|
@ -418,17 +456,43 @@ public class Process {
|
||||||
int displayType = pPara.getAD_Reference_ID();
|
int displayType = pPara.getAD_Reference_ID();
|
||||||
|
|
||||||
String valueString = null;
|
String valueString = null;
|
||||||
Object ob = fmap.get( key );
|
DataField dataField = fmap.get( key );
|
||||||
if (ob!=null )
|
if (dataField != null && !Util.isEmpty(dataField.getVal()))
|
||||||
valueString = ob.toString();
|
{
|
||||||
|
valueString = dataField.getVal();
|
||||||
|
if (requestCtx != null && valueString.charAt(0) == '@')
|
||||||
|
{
|
||||||
|
Object value = ModelADServiceImpl.parseVatriable(m_cs, requestCtx, iPara.getParameterName(), valueString);
|
||||||
|
valueString = value != null ? value.toString() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dataField != null && !Util.isEmpty(dataField.getLval()))
|
||||||
|
valueString = getLookupValue(pPara, dataField);
|
||||||
|
|
||||||
|
if (isDataURI(valueString))
|
||||||
|
{
|
||||||
|
valueString = "";
|
||||||
|
iPara.setInfo("binary");
|
||||||
|
}
|
||||||
|
|
||||||
String valueString2 = null;
|
String valueString2 = null;
|
||||||
if (pPara.isRange())
|
if (pPara.isRange())
|
||||||
{
|
{
|
||||||
ob = fmap.get( key+"_2" );
|
dataField = fmap.get( key+"_2" );
|
||||||
if (ob!=null)
|
if (dataField != null && !Util.isEmpty(dataField.getVal()))
|
||||||
valueString2 = ob.toString();
|
{
|
||||||
|
valueString2 = dataField.toString();
|
||||||
|
if (requestCtx != null && valueString2.charAt(0) == '@')
|
||||||
|
{
|
||||||
|
Object value = ModelADServiceImpl.parseVatriable(m_cs, requestCtx, iPara.getParameterName(), valueString2);
|
||||||
|
valueString2 = value != null ? value.toString() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dataField != null && !Util.isEmpty(dataField.getLval()))
|
||||||
|
valueString2 = getLookupValue(pPara, dataField);
|
||||||
}
|
}
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("fillParameter - " + key + " = " + valueString);
|
if (log.isLoggable(Level.FINE)) log.fine("fillParameter - " + key + " = " + valueString);
|
||||||
|
|
||||||
Object value = valueString;
|
Object value = valueString;
|
||||||
if (valueString != null && valueString.length() == 0)
|
if (valueString != null && valueString.length() == 0)
|
||||||
value = null;
|
value = null;
|
||||||
|
@ -556,92 +620,24 @@ public class Process {
|
||||||
return pInstance;
|
return pInstance;
|
||||||
} // fillParameter
|
} // fillParameter
|
||||||
|
|
||||||
/*
|
private static String getLookupValue(MProcessPara pPara, DataField dataField) {
|
||||||
static ReportServer server = null;
|
MLookup lookup = null;
|
||||||
|
try {
|
||||||
private void jasperReport(HttpServletRequest request, HttpServletResponse response, Properties ctx, int AD_Process_ID, int AD_Instance_ID) throws Exception
|
lookup = MLookupFactory.get(pPara.getCtx(),0,0,pPara.getAD_Reference_ID(),Env.getLanguage(pPara.getCtx()),pPara.getColumnName(),pPara.getAD_Reference_Value_ID(),false,null);
|
||||||
{
|
} catch (Exception e) {
|
||||||
|
throw new IdempiereServiceFault("Exception in resolving lookup ", new QName(
|
||||||
MProcess process = MProcess.get (ctx, AD_Process_ID);
|
"LookupResolutionFailed"));
|
||||||
// need to check if Role can access
|
|
||||||
if (process == null)
|
|
||||||
throw new Exception( "Brak procesu" );
|
|
||||||
|
|
||||||
MPInstance pInstance = new MPInstance( ctx, AD_Instance_ID, null );
|
|
||||||
if (pInstance == null)
|
|
||||||
throw new Exception( "Brak intancji procesu" );
|
|
||||||
|
|
||||||
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID());
|
|
||||||
pi.setAD_User_ID(pInstance.getAD_User_ID());
|
|
||||||
pi.setAD_Client_ID(pInstance.getAD_Client_ID());
|
|
||||||
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
|
|
||||||
pi.setRecord_ID( pInstance.getRecord_ID() );
|
|
||||||
|
|
||||||
jasperReport( request, response, ctx, pi);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Procedura obsluguje raporty jasper - przekazuje wynik raportu w postaci PDF
|
|
||||||
* @param request
|
|
||||||
* @param response
|
|
||||||
* @param ctx
|
|
||||||
* @param pi
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
private void jasperReport(HttpServletRequest request, HttpServletResponse response, Properties ctx, ProcessInfo pi)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JasperPrint jasperPrint = getJasperReportPrint( ctx, pi );
|
|
||||||
|
|
||||||
ServletOutputStream output = response.getOutputStream();
|
|
||||||
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jasperPrint, output);
|
|
||||||
|
|
||||||
int bufferSize = 2048; // 2k Buffer
|
|
||||||
|
|
||||||
//response.setContentType(mimeType.getMimeType());
|
|
||||||
response.setBufferSize(bufferSize);
|
|
||||||
|
|
||||||
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
|
|
||||||
response.setHeader("Pragma","no-cache"); //HTTP 1.0
|
|
||||||
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
|
|
||||||
|
|
||||||
response.setContentType( "application/pdf" );
|
|
||||||
|
|
||||||
//response.setHeader("Content-disposition","inline;filename=generated.pdf");
|
|
||||||
// response.setHeader("Pragma","no-cache");
|
|
||||||
// response.setHeader("Cache-Control", "no-cache");
|
|
||||||
// response.setHeader("Cache-Control","no-store" );
|
|
||||||
// response.setDateHeader("Expires", -1);
|
|
||||||
// response.setHeader("Content-Type","application/pdf" );
|
|
||||||
//response.setContentType( "application/pdf" );
|
|
||||||
//response.setHeader("Content-Type","application/pdf" );
|
|
||||||
|
|
||||||
|
|
||||||
output.flush();
|
|
||||||
output.close();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (JRException e)
|
|
||||||
{
|
|
||||||
log.saveError("ReportStarter.startProcess: Can not run report - ", e);
|
|
||||||
return;
|
|
||||||
//return e.getMessage();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
log.saveError("ReportStarter.startProcess: Can not run report - ", ex);
|
|
||||||
return;
|
|
||||||
// return ex.getMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String sql = ADLookup.getDirectAccessSQL(lookup, dataField.getLval().toUpperCase());
|
||||||
|
sql = sql + " ORDER BY AD_Client_ID DESC ";
|
||||||
|
int id = DB.getSQLValue(null, sql);
|
||||||
|
if (id > 0)
|
||||||
|
return Integer.toString(id);
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static JasperPrint getJasperReportPrint(Properties ctx, ProcessInfo pi)
|
private static JasperPrint getJasperReportPrint(Properties ctx, ProcessInfo pi)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -721,13 +717,6 @@ public class Process {
|
||||||
//ADialog.error(0, null, "NoDocPrintFormat");
|
//ADialog.error(0, null, "NoDocPrintFormat");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/* if (IsDirectPrint)
|
|
||||||
{
|
|
||||||
re.print ();
|
|
||||||
ReportEngine.printConfirm (type, Record_ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
new Viewer(re);*/
|
|
||||||
|
|
||||||
return re;
|
return re;
|
||||||
} // StartDocumentPrint
|
} // StartDocumentPrint
|
||||||
|
@ -748,12 +737,6 @@ public class Process {
|
||||||
pi.setSummary("No ReportEngine");
|
pi.setSummary("No ReportEngine");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//if (IsDirectPrint)
|
|
||||||
//{
|
|
||||||
// re.print();
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
// new Viewer(re);
|
|
||||||
return re;
|
return re;
|
||||||
} // startStandardReport
|
} // startStandardReport
|
||||||
|
|
||||||
|
@ -780,6 +763,16 @@ public class Process {
|
||||||
return startDocumentPrint (ReportEngine.CHECK, C_PaySelectionCheck_ID);
|
return startDocumentPrint (ReportEngine.CHECK, C_PaySelectionCheck_ID);
|
||||||
} // startCheckPrint
|
} // startCheckPrint
|
||||||
|
|
||||||
|
private static boolean isDataURI(String s)
|
||||||
|
{
|
||||||
|
if (Util.isEmpty(s)) return false;
|
||||||
|
|
||||||
|
if (s.startsWith("data:") && s.indexOf(";base64,") > 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Financial Report.
|
* Start Financial Report.
|
||||||
* @param pi Process Info
|
* @param pi Process Info
|
||||||
|
|
Loading…
Reference in New Issue