Search in sources :

Example 6 with DataField

use of org.idempiere.adInterface.x10.DataField in project idempiere by idempiere.

the class ModelADServiceImpl method getList.

public WindowTabDataDocument getList(ModelGetListRequestDocument req) {
    try {
        getCompiereService().connect();
        WindowTabDataDocument resdoc = WindowTabDataDocument.Factory.newInstance();
        WindowTabData res = resdoc.addNewWindowTabData();
        DataSet ds = res.addNewDataSet();
        ModelGetList modelGetList = req.getModelGetListRequest().getModelGetList();
        String serviceType = modelGetList.getServiceType();
        int cnt = 0;
        ADLoginRequest reqlogin = req.getModelGetListRequest().getADLoginRequest();
        String err = login(reqlogin, webServiceName, "getList", serviceType);
        if (err != null && err.length() > 0) {
            res.setError(err);
            res.setErrorInfo(err);
            res.setSuccess(false);
            return resdoc;
        }
        int roleid = reqlogin.getRoleID();
        // Validate parameters
        try {
            modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", modelGetList.getADReferenceID()));
        } catch (XmlValueOutOfRangeException e) {
            // Catch the exception when the Reference ID is not an Integer
            String refUU = getUUIDValue(modelGetList.xgetADReferenceID());
            if (refUU == null) {
                throw e;
            }
            modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", 0, refUU));
        }
        modelGetList.setFilter(validateParameter("Filter", modelGetList.getFilter()));
        int ref_id = modelGetList.getADReferenceID();
        String filter = modelGetList.getFilter();
        if (filter == null || filter.length() == 0)
            filter = "";
        else
            filter = " AND " + filter;
        CompiereService m_cs = getCompiereService();
        Properties ctx = m_cs.getCtx();
        MReference ref = MReference.get(ctx, ref_id);
        String sql = null;
        ArrayList<String> listColumnNames = new ArrayList<String>();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        MWebServiceType m_webservicetype = getWebServiceType();
        if (MReference.VALIDATIONTYPE_ListValidation.equals(ref.getValidationType())) {
            // Fill List Reference
            String ad_language = Env.getAD_Language(ctx);
            boolean isBaseLanguage = Env.isBaseLanguage(ad_language, "AD_Ref_List");
            sql = isBaseLanguage ? "SELECT AD_Ref_List.AD_Ref_List_ID, AD_Ref_List.Value, AD_Ref_List.Name, AD_Ref_List.Description " + "FROM AD_Ref_List " + "WHERE AD_Ref_List.AD_Reference_ID=? AND AD_Ref_List.IsActive='Y' " + filter + " ORDER BY AD_Ref_List.Name" : "SELECT AD_Ref_List.AD_Ref_List_ID, AD_Ref_List.Value, AD_Ref_List_Trl.Name, AD_Ref_List_Trl.Description " + "FROM AD_Ref_List, AD_Ref_List_Trl " + "WHERE AD_Ref_List.AD_Reference_ID=? AND AD_Ref_List.IsActive='Y' AND AD_Ref_List_Trl.AD_Language=? AND AD_Ref_List.AD_Ref_List_ID=AD_Ref_List_Trl.AD_Ref_List_ID " + filter + " ORDER BY AD_Ref_List_Trl.Name";
            listColumnNames.add("AD_Ref_List_ID");
            listColumnNames.add("Value");
            listColumnNames.add("Name");
            listColumnNames.add("Description");
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, ref_id);
                if (!isBaseLanguage)
                    pstmt.setString(2, ad_language);
                rs = pstmt.executeQuery();
            } catch (SQLException e) {
                res.setError(e.getMessage());
                res.setErrorInfo(sql);
                res.setSuccess(false);
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
                throw new IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
            }
        } else if (MReference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) {
            // Fill values from a reference table
            MRole role = MRole.get(ctx, roleid);
            MRefTable rt = MRefTable.get(ctx, ref_id);
            if (rt == null || rt.get_ID() == 0)
                throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": reference table " + ref_id + " not found", new QName("getList"));
            MTable table = new MTable(ctx, rt.getAD_Table_ID(), null);
            MColumn column = new MColumn(ctx, rt.getAD_Key(), null);
            // TODO: if any value or identifier column is translated, then get them from trl table (and client has multilanguage documents enabled)
            sql = "SELECT " + column.getColumnName();
            listColumnNames.add(column.getColumnName());
            if (rt.isValueDisplayed()) {
                sql += ",Value";
                listColumnNames.add("Value");
            }
            String sqlident = "SELECT ColumnName FROM AD_Column WHERE AD_Table_ID=? AND IsActive='Y' AND IsIdentifier='Y' ORDER BY SeqNo";
            PreparedStatement pstmtident = null;
            ResultSet rsident = null;
            try {
                pstmtident = DB.prepareStatement(sqlident, null);
                pstmtident.setInt(1, rt.getAD_Table_ID());
                rsident = pstmtident.executeQuery();
                while (rsident.next()) {
                    String colnameident = rsident.getString("ColumnName");
                    if (rt.isValueDisplayed() && colnameident.equalsIgnoreCase("Value")) {
                    // Value already added
                    } else {
                        sql += "," + colnameident;
                        listColumnNames.add(colnameident);
                    }
                }
            } catch (Exception e) {
            // ignore this exception
            } finally {
                DB.close(rsident, pstmtident);
                rsident = null;
                pstmtident = null;
            }
            sql += " FROM " + table.getTableName() + " WHERE IsActive='Y'";
            sql = role.addAccessSQL(sql, table.getTableName(), true, true);
            sql += filter;
            if (rt.getWhereClause() != null && rt.getWhereClause().length() > 0)
                sql += " AND " + rt.getWhereClause();
            if (rt.getOrderByClause() != null && rt.getOrderByClause().length() > 0)
                sql += " ORDER BY " + rt.getOrderByClause();
            try {
                pstmt = DB.prepareStatement(sql, null);
                rs = pstmt.executeQuery();
            } catch (SQLException e) {
                res.setError(e.getMessage());
                res.setErrorInfo(sql);
                res.setSuccess(false);
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
                throw new IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
            }
        } else {
        // Don't fill - wrong type
        }
        if (rs != null) {
            try {
                while (rs.next()) {
                    cnt++;
                    // Add values to the dataset
                    DataRow dr = ds.addNewDataRow();
                    for (String listColumnName : listColumnNames) {
                        if (m_webservicetype.isOutputColumnNameAllowed(listColumnName)) {
                            DataField dfid = dr.addNewField();
                            dfid.setColumn(listColumnName);
                            dfid.setVal(rs.getString(listColumnName));
                        }
                    }
                }
                res.setSuccess(true);
            } catch (SQLException e) {
                res.setError(e.getMessage());
                res.setErrorInfo(sql);
                res.setSuccess(false);
                throw new IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
        }
        res.setRowCount(cnt);
        res.setNumRows(cnt);
        res.setTotalRows(cnt);
        res.setStartRow(1);
        return resdoc;
    } finally {
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) SQLException(java.sql.SQLException) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) ModelGetList(org.idempiere.adInterface.x10.ModelGetList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) MRefTable(org.compiere.model.MRefTable) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ResultSet(java.sql.ResultSet) MReference(org.compiere.model.MReference) MColumn(org.compiere.model.MColumn) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) PreparedStatement(java.sql.PreparedStatement) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField)

Example 7 with DataField

use of org.idempiere.adInterface.x10.DataField in project idempiere by idempiere.

the class ModelADServiceImpl method scanFields.

public StandardResponseDocument scanFields(DataField[] fields, MWebServiceType m_webservicetype, PO po, POInfo poinfo, Trx trx, StandardResponse resp, StandardResponseDocument ret) {
    Map<String, Object> requestCtx = getRequestCtx();
    // Clear ctx
    Env.clearWinContext(Env.getCtx(), 0);
    for (DataField field : fields) {
        // Implement lookup
        X_WS_WebServiceFieldInput fieldInput = m_webservicetype.getFieldInput(field.getColumn());
        if (fieldInput != null) {
            // Is ctx variable
            if (fieldInput.getAD_Column_ID() == 0 && fieldInput.getColumnName() != null) {
                String varName = fieldInput.getColumnName();
                Class<?> columnClass = getVariableType(varName, fieldInput.getAD_Reference_ID());
                Object objVal = null;
                String val = field.getVal();
                if (val != null && val.length() > 0 && val.charAt(0) == '@')
                    objVal = parseVariable(field.getVal(), po, poinfo, requestCtx);
                else
                    objVal = convertToObj(field.getVal(), columnClass, varName);
                requestCtx.put(varName, objVal);
            } else {
                int idxcol = po.get_ColumnIndex(field.getColumn());
                if (idxcol < 0) {
                    // defined in security
                    return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " does not exist");
                } else {
                    try {
                        setValueAccordingToClass(po, poinfo, field, idxcol, fieldInput);
                    } catch (IdempiereServiceFault e) {
                        log.log(Level.WARNING, "Error setting value", e);
                        return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " value could not be set: " + e.getLocalizedMessage());
                    }
                }
            }
        } else {
            return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed");
        }
    }
    return null;
}
Also used : X_WS_WebServiceFieldInput(org.idempiere.webservices.model.X_WS_WebServiceFieldInput) DataField(org.idempiere.adInterface.x10.DataField) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault)

Example 8 with DataField

use of org.idempiere.adInterface.x10.DataField in project idempiere by idempiere.

the class ModelADServiceImpl method createData.

public StandardResponseDocument createData(ModelCRUDRequestDocument req) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
        StandardResponse resp = ret.addNewStandardResponse();
        ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
        String serviceType = modelCRUD.getServiceType();
        ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
        String err = login(reqlogin, webServiceName, "createData", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            resp.setIsError(true);
            return ret;
        }
        // Validate parameters vs service type
        try {
            validateCRUD(modelCRUD);
        } catch (IdempiereServiceFault e) {
            resp.setError(e.getMessage());
            resp.setIsError(true);
            return ret;
        }
        String tableName = modelCRUD.getTableName();
        CompiereService m_cs = getCompiereService();
        Properties ctx = m_cs.getCtx();
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelCreateData");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_createData");
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
        PO po = table.getPO(0, trxName);
        if (po == null)
            return rollbackAndSetError(trx, resp, ret, true, "Cannot create PO for " + tableName);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        DataRow dr = modelCRUD.getDataRow();
        MWebServiceType m_webservicetype = getWebServiceType();
        Map<String, Object> requestCtx = getRequestCtx();
        DataField[] fields = dr.getFieldArray();
        StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, po, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        retResp = scanFields(fields, m_webservicetype, po, poinfo, trx, resp, ret);
        if (retResp != null)
            return retResp;
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_AFTER_PARSE, po, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_SAVE, po, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        if (!po.validForeignKeys())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
        if (!po.save())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_AFTER_SAVE, po, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        int recordID = po.get_ID();
        resp.setRecordID(recordID);
        // Update ctx variable for consecutive calls
        if (requestCtx != null) {
            requestCtx.put(po.get_TableName(), po);
        }
        // close the trx
        if (manageTrx && !trx.commit())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
        setOuputFields(resp, m_webservicetype, po, poinfo);
        return ret;
    } finally {
        if (manageTrx && trx != null)
            trx.close();
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 9 with DataField

use of org.idempiere.adInterface.x10.DataField in project idempiere by idempiere.

the class ModelADServiceImpl method createUpdateData.

// createData
public StandardResponseDocument createUpdateData(ModelCRUDRequestDocument req) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
        StandardResponse resp = ret.addNewStandardResponse();
        ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
        String serviceType = modelCRUD.getServiceType();
        ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
        String err = login(reqlogin, webServiceName, "createData", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            resp.setIsError(true);
            return ret;
        }
        // Validate parameters vs service type
        try {
            validateCRUD(modelCRUD);
        } catch (IdempiereServiceFault e) {
            resp.setError(e.getMessage());
            resp.setIsError(true);
            return ret;
        }
        String tableName = modelCRUD.getTableName();
        CompiereService m_cs = getCompiereService();
        Properties ctx = m_cs.getCtx();
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelCreateData");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_createUpdateData");
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
        DataRow dr = modelCRUD.getDataRow();
        DataField[] fields = dr.getFieldArray();
        PO holderPo = table.getPO(0, trxName);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        MWebServiceType m_webservicetype = getWebServiceType();
        Map<String, Object> requestCtx = getRequestCtx();
        StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, holderPo, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        retResp = scanFields(fields, m_webservicetype, holderPo, poinfo, trx, resp, ret);
        if (retResp != null)
            return retResp;
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_AFTER_PARSE, holderPo, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        boolean isCreate = false;
        boolean isUpdate = false;
        String action = modelCRUD.getAction().toString();
        if (action.equals("Create"))
            isCreate = true;
        if (action.equals("Update"))
            isUpdate = true;
        if (action.equals("CreateUpdate")) {
            isCreate = true;
            isUpdate = true;
        }
        ArrayList<String> identifierList = m_webservicetype.getKeyColumns();
        // For update it is mandatory to pass key column
        if (isUpdate && identifierList.size() == 0) {
            return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": There is no key column found ");
        }
        // Check for existing element
        int record_id = 0;
        ArrayList<Object> resovedValue = new ArrayList<Object>();
        if (identifierList.size() > 0) {
            StringBuilder sqlBuilder = new StringBuilder("Select ");
            sqlBuilder.append(table.getTableName()).append("_ID from ").append(table.getTableName()).append(" ot Where ");
            ArrayList<Object> sqlParaList = new ArrayList<Object>();
            for (String colName : identifierList) {
                X_WS_WebServiceFieldInput fieldInput = m_webservicetype.getFieldInput(colName);
                if (fieldInput.getIdentifierLogic() == null) {
                    if (holderPo.get_Value(colName) == null && fieldInput.isNullIdentifier()) {
                        sqlBuilder.append(" ot.").append(colName).append(" Is Null AND ");
                    } else if (holderPo.get_Value(colName) == null) {
                        return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": Record Identifier column " + colName + " must be set");
                    } else {
                        sqlBuilder.append(" ot.").append(colName).append("=? AND ");
                        sqlParaList.add(holderPo.get_Value(colName));
                        resovedValue.add(holderPo.get_Value(colName));
                    }
                } else {
                    // SQL
                    String sql = parseSQL(fieldInput.getIdentifierLogic(), sqlParaList, holderPo, poinfo, requestCtx);
                    sqlBuilder.append(" ot.").append(colName).append(" = (").append(sql).append(") AND ");
                    resovedValue.add("DYN SQL");
                }
            }
            sqlBuilder.append(" ot.AD_Client_ID= ?");
            sqlParaList.add(Env.getAD_Client_ID(Env.getCtx()));
            String sql = sqlBuilder.toString();
            if (log.isLoggable(Level.INFO))
                log.info("Web service type " + m_webservicetype.getValue() + "SQL to check existing record " + sql);
            try {
                record_id = DB.getSQLValueEx(trxName, sql, sqlParaList);
            } catch (Exception e) {
                log.log(Level.SEVERE, "ExistingRecordCheck: Exception while executing SQL :" + sql);
                return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + " Exception while executing sql :" + sql);
            }
        }
        if (record_id == -1)
            record_id = 0;
        if (!isCreate && record_id == 0) {
            resp.setError("No Record to update for " + table.getTableName() + " with (" + identifierList.toString() + ") = (" + resovedValue.toString() + ")");
            resp.setIsError(true);
            return ret;
        }
        if (record_id > 0 && !isUpdate) {
            resp.setError("Record already presents with " + table.getTableName() + "_ID = " + record_id);
            resp.setIsError(true);
            return ret;
        }
        PO po = table.getPO(record_id, trxName);
        if (po == null)
            return rollbackAndSetError(trx, resp, ret, true, "Cannot create PO for " + tableName);
        if (po.get_ColumnIndex("Processed") >= 0 && po.get_ValueAsBoolean("Processed")) {
            resp.setError("Record not updatable for " + table.getTableName() + "_ID = " + record_id);
            resp.setIsError(true);
            return ret;
        }
        // Setting value back from holder to new persistent po
        for (DataField field : fields) {
            int indx = poinfo.getColumnIndex(field.getColumn());
            if (indx != -1) {
                po.set_ValueNoCheck(field.getColumn(), holderPo.get_Value(field.getColumn()));
            }
        }
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_SAVE, holderPo, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        if (!po.validForeignKeys())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
        if (!po.save())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_AFTER_SAVE, holderPo, fields, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        int recordID = po.get_ID();
        resp.setRecordID(recordID);
        // Update ctx variable for consecutive calls
        if (requestCtx != null) {
            requestCtx.put(po.get_TableName(), po);
        }
        // close the trx
        if (manageTrx && !trx.commit())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
        setOuputFields(resp, m_webservicetype, po, poinfo);
        return ret;
    } finally {
        if (manageTrx && trx != null)
            trx.close();
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) ArrayList(java.util.ArrayList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) Trx(org.compiere.util.Trx) X_WS_WebServiceFieldInput(org.idempiere.webservices.model.X_WS_WebServiceFieldInput) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) PO(org.compiere.model.PO)

Example 10 with DataField

use of org.idempiere.adInterface.x10.DataField in project idempiere by idempiere.

the class Process method fillParameter.

// createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process, Map<String, Object> requestCtx) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap<String, DataField> fmap = new HashMap<String, DataField>();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i]);
    // 
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        int displayType = pPara.getAD_Reference_ID();
        String valueString = null;
        DataField dataField = fmap.get(key);
        if (dataField != null && !Util.isEmpty(dataField.getVal())) {
            valueString = dataField.getVal();
            if (requestCtx != null && valueString.charAt(0) == '@') {
                Object value = ModelADServiceImpl.parseVariable(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;
        if (pPara.isRange()) {
            dataField = fmap.get(key + "_2");
            if (dataField != null && !Util.isEmpty(dataField.getVal())) {
                valueString2 = dataField.getVal();
                if (requestCtx != null && valueString2.charAt(0) == '@') {
                    Object value = ModelADServiceImpl.parseVariable(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);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.isList(displayType) || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
            value = null;
        // No Value
        if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
            if (pPara.isMandatory())
                throw new Exception(" Parameter " + pPara.getName() + " is required.");
        } else {
            // Convert to Type
            try {
                if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    if (log.isLoggable(Level.FINE))
                        log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                    if (pPara.isRange()) {
                        bd = null;
                        bd = new BigDecimal(valueString2.toString());
                        iPara.setP_Number_To(bd);
                    }
                } else if (DisplayType.isDate(displayType)) {
                    java.util.Date d;
                    if (value.toString().length() > 0) {
                        if (displayType == DisplayType.DateTime) {
                            try {
                                d = m_cs.dateTimeFormatJDBC.parse(value.toString());
                            } catch (ParseException e) {
                                d = m_cs.dateTimeFormat.parse(value.toString());
                            }
                        } else if (displayType == DisplayType.Time) {
                            try {
                                d = m_cs.timeFormatJDBC.parse(value.toString());
                            } catch (ParseException e) {
                                d = m_cs.timeFormat.parse(value.toString());
                            }
                        } else {
                            try {
                                d = m_cs.dateFormatJDBC.parse(value.toString());
                            } catch (ParseException e) {
                                d = m_cs.dateFormat.parse(value.toString());
                            }
                        }
                        Timestamp ts = new Timestamp(d.getTime());
                        iPara.setP_Date(ts);
                        if (log.isLoggable(Level.FINE))
                            log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                    }
                    if (pPara.isRange()) {
                        if (valueString2 != null && valueString2.length() > 0) {
                            if (displayType == DisplayType.DateTime) {
                                try {
                                    d = m_cs.dateTimeFormatJDBC.parse(valueString2);
                                } catch (ParseException e) {
                                    d = m_cs.dateTimeFormat.parse(valueString2);
                                }
                            } else if (displayType == DisplayType.Time) {
                                try {
                                    d = m_cs.timeFormatJDBC.parse(valueString2);
                                } catch (ParseException e) {
                                    d = m_cs.timeFormat.parse(valueString2);
                                }
                            } else {
                                try {
                                    d = m_cs.dateFormatJDBC.parse(valueString2);
                                } catch (ParseException e) {
                                    d = m_cs.dateFormat.parse(valueString2);
                                }
                            }
                            Timestamp ts = new Timestamp(d.getTime());
                            iPara.setP_Date_To(ts);
                            if (log.isLoggable(Level.FINE))
                                log.fine("fillParameterTo - " + key + " = " + valueString + " (=" + ts + "=)");
                        }
                    }
                } else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
                    String bv = "N";
                    if (value == null)
                        bv = "N";
                    else // if (value.toString().toLowerCase().charAt(0)=='t')
                    {
                        if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
                            bv = "Y";
                        else
                            bv = "N";
                    }
                    // bv ="Y";
                    iPara.setP_String(bv);
                } else {
                    iPara.setP_String(value.toString());
                }
                if (// kolec - ustawia wartosc dla parametru Lookup
                pPara.isLookup()) {
                    Lookup lok = pPara.getLookup();
                    if (lok != null) {
                        NamePair np = lok.getDirect(value, false, false);
                        if (np != null) {
                            iPara.setInfo(np.getName());
                        }
                    }
                } else {
                    if (value != null)
                        iPara.setInfo(value.toString());
                    if (valueString2 != null)
                        iPara.setInfo_To(valueString2);
                }
                // 
                iPara.saveEx();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    // not null
    }
    // instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.saveEx();
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) HashMap(java.util.HashMap) NamePair(org.compiere.util.NamePair) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) ParseException(java.text.ParseException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(org.idempiere.adInterface.x10.DataField) Lookup(org.compiere.model.Lookup) MLookup(org.compiere.model.MLookup) ParseException(java.text.ParseException)

Aggregations

DataField (org.idempiere.adInterface.x10.DataField)10 DataRow (org.idempiere.adInterface.x10.DataRow)7 MTable (org.compiere.model.MTable)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 PO (org.compiere.model.PO)5 DataSet (org.idempiere.adInterface.x10.DataSet)5 ModelCRUD (org.idempiere.adInterface.x10.ModelCRUD)5 WindowTabData (org.idempiere.adInterface.x10.WindowTabData)5 WindowTabDataDocument (org.idempiere.adInterface.x10.WindowTabDataDocument)5 IdempiereServiceFault (org.idempiere.webservices.fault.IdempiereServiceFault)5 POInfo (org.compiere.model.POInfo)4 Trx (org.compiere.util.Trx)4 ADLoginRequest (org.idempiere.adInterface.x10.ADLoginRequest)4 MWebServiceType (org.idempiere.webservices.model.MWebServiceType)4 SQLException (java.sql.SQLException)3 QName (javax.xml.namespace.QName)3 XmlValueOutOfRangeException (org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException)3 StandardResponse (org.idempiere.adInterface.x10.StandardResponse)3 URL (java.net.URL)2