Search in sources :

Example 1 with XFireFault

use of org.codehaus.xfire.fault.XFireFault in project adempiere by adempiere.

the class ModelADServiceImpl method updateData.

public StandardResponseDocument updateData(ModelCRUDRequestDocument req) throws XFireFault {
    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 = modelLogin(reqlogin, webServiceName, "updateData", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        resp.setIsError(true);
        return ret;
    }
    // Validate parameters vs service type
    validateCRUD(modelCRUD);
    String tableName = modelCRUD.getTableName();
    int recordID = modelCRUD.getRecordID();
    resp.setRecordID(recordID);
    Properties ctx = m_cs.getM_ctx();
    // start a trx
    String trxName = Trx.createTrxName("ws_modelUpdateData");
    Trx trx = Trx.get(trxName, false);
    // 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(recordID, trxName);
    if (po == null)
        return rollbackAndSetError(trx, resp, ret, true, "No Record " + recordID + " in " + tableName);
    POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
    DataRow dr = modelCRUD.getDataRow();
    for (DataField field : dr.getFieldList()) {
        // TODO: Implement lookup
        if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
            int idxcol = po.get_ColumnIndex(field.getColumn());
            if (idxcol < 0) {
                // The column doesn't exist - it must exist as it's 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);
                } catch (XFireFault 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");
        }
    }
    if (!po.save())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
    // close the trx
    if (!trx.commit())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after delete record " + recordID + " in " + tableName);
    trx.close();
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) StandardResponse(pl.x3E.adInterface.StandardResponse) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) StandardResponseDocument(pl.x3E.adInterface.StandardResponseDocument) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 2 with XFireFault

use of org.codehaus.xfire.fault.XFireFault in project adempiere by adempiere.

the class ModelADServiceImpl method setValueAccordingToClass.

// createData
private void setValueAccordingToClass(PO po, POInfo poinfo, DataField field, int idxcol) throws XFireFault {
    // Evaluate the type of the column and assign a proper variable
    Class columnClass = poinfo.getColumnClass(idxcol);
    Object value = null;
    if (field.getVal() == null || field.getVal().length() == 0) {
        value = null;
    } else if (columnClass == Boolean.class) {
        if ("Y".equalsIgnoreCase(field.getVal()) || "true".equalsIgnoreCase(field.getVal()))
            value = new Boolean(true);
        else if ("N".equalsIgnoreCase(field.getVal()) || "false".equalsIgnoreCase(field.getVal()))
            value = new Boolean(false);
        else
            throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " wrong value " + field.getVal(), new QName("setValueAccordingToClass"));
    } else if (columnClass == Integer.class) {
        try {
            value = Integer.parseInt(field.getVal());
        } catch (NumberFormatException e) {
            throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " for " + field.getColumn(), e.getCause(), new QName("setValueAccordingToClass"));
        }
    } else if (columnClass == BigDecimal.class) {
        try {
            value = new BigDecimal(field.getVal());
        } catch (Exception e) {
            throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " for " + field.getColumn(), e.getCause(), new QName("setValueAccordingToClass"));
        }
    } else if (columnClass == Timestamp.class) {
        try {
            value = Timestamp.valueOf(field.getVal());
        } catch (Exception e) {
            throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " for " + field.getColumn(), e.getCause(), new QName("setValueAccordingToClass"));
        }
    } else if (columnClass == byte[].class) {
        throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " LOB not supported", new QName("setValueAccordingToClass"));
    } else {
        value = field.getVal();
    }
    if (!po.set_ValueOfColumnReturningBoolean(field.getColumn(), value))
        throw new XFireFault("Cannot set value of column " + field.getColumn(), new QName("setValueAccordingToClass"));
}
Also used : QName(javax.xml.namespace.QName) XFireFault(org.codehaus.xfire.fault.XFireFault) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Example 3 with XFireFault

use of org.codehaus.xfire.fault.XFireFault in project adempiere by adempiere.

the class ModelADServiceImpl method createData.

public StandardResponseDocument createData(ModelCRUDRequestDocument req) throws XFireFault {
    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 = modelLogin(reqlogin, webServiceName, "createData", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        resp.setIsError(true);
        return ret;
    }
    // Validate parameters vs service type
    validateCRUD(modelCRUD);
    String tableName = modelCRUD.getTableName();
    Properties ctx = m_cs.getM_ctx();
    // start a trx
    String trxName = Trx.createTrxName("ws_modelCreateData");
    Trx trx = Trx.get(trxName, false);
    // 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();
    for (DataField field : dr.getFieldList()) {
        // TODO: Implement lookup
        if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
            int idxcol = po.get_ColumnIndex(field.getColumn());
            if (idxcol < 0) {
                // The column doesn't exist - it must exist as it's 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);
                } catch (XFireFault 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");
        }
    }
    if (!po.save())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
    int recordID = po.get_ID();
    resp.setRecordID(recordID);
    // close the trx
    if (!trx.commit())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
    trx.close();
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) StandardResponse(pl.x3E.adInterface.StandardResponse) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) StandardResponseDocument(pl.x3E.adInterface.StandardResponseDocument) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 4 with XFireFault

use of org.codehaus.xfire.fault.XFireFault in project adempiere by adempiere.

the class ModelADServiceImpl method authenticate.

private String authenticate(String webServiceValue, String methodValue, String serviceTypeValue) throws XFireFault {
    m_webservice = MWebService.get(m_cs.getM_ctx(), webServiceValue);
    if (m_webservice == null || !m_webservice.isActive())
        return "Web Service " + webServiceValue + " not registered";
    m_webservicemethod = m_webservice.getMethod(methodValue);
    if (m_webservicemethod == null || !m_webservicemethod.isActive())
        return "Method " + methodValue + " not registered";
    m_webservicetype = null;
    final String sql = "SELECT * FROM WS_WebServiceType " + //"AND WS_WebService_ID=? " +
    "WHERE WS_WebService_ID=? " + /** End Carlos Parada */
    "AND WS_WebServiceMethod_ID=? " + "AND Value=? " + "AND IsActive='Y'";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        /** 2014-11-05 Carlos Parada Remove Client Filter */
        /*pstmt.setInt(1, m_cs.getM_AD_Client_ID());
			pstmt.setInt(2, m_webservice.getWS_WebService_ID());
			pstmt.setInt(3, m_webservicemethod.getWS_WebServiceMethod_ID());
			pstmt.setString(4, serviceTypeValue);*/
        pstmt.setInt(1, m_webservice.getWS_WebService_ID());
        pstmt.setInt(2, m_webservicemethod.getWS_WebServiceMethod_ID());
        pstmt.setString(3, serviceTypeValue);
        /** End Carlos Parada */
        System.out.println("m_webservice.getWS_WebService_ID()" + m_webservice.getWS_WebService_ID());
        System.out.println("m_webservicemethod.getWS_WebServiceMethod_ID()" + m_webservicemethod.getWS_WebServiceMethod_ID());
        System.out.println("serviceTypeValue" + serviceTypeValue);
        rs = pstmt.executeQuery();
        if (rs.next())
            m_webservicetype = new MWebServiceType(m_cs.getM_ctx(), rs, null);
    } catch (Exception e) {
        throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("authenticate"));
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (m_webservicetype == null)
        return "Service type " + serviceTypeValue + " not configured";
    return null;
}
Also used : MWebServiceType(org.compiere.model.MWebServiceType) QName(javax.xml.namespace.QName) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) XFireFault(org.codehaus.xfire.fault.XFireFault) SQLException(java.sql.SQLException)

Example 5 with XFireFault

use of org.codehaus.xfire.fault.XFireFault in project adempiere by adempiere.

the class ModelADServiceImpl method getList.

public WindowTabDataDocument getList(ModelGetListRequestDocument req) throws XFireFault {
    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 = modelLogin(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
    modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", modelGetList.getADReferenceID()));
    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;
    Properties ctx = m_cs.getM_ctx();
    X_AD_Reference ref = new X_AD_Reference(ctx, ref_id, null);
    String sql = null;
    ArrayList<String> listColumnNames = new ArrayList<String>();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    if (X_AD_Reference.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 XFireFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
        }
    } else if (X_AD_Reference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) {
        // Fill values from a reference table
        MRole role = new MRole(ctx, roleid, null);
        String sqlrt = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID=?";
        MRefTable rt = null;
        PreparedStatement pstmtrt = null;
        ResultSet rsrt = null;
        try {
            pstmtrt = DB.prepareStatement(sqlrt, null);
            pstmtrt.setInt(1, ref_id);
            rsrt = pstmtrt.executeQuery();
            if (rsrt.next())
                rt = new MRefTable(ctx, rsrt, null);
        } catch (Exception e) {
        // ignore this exception
        } finally {
            DB.close(rsrt, pstmtrt);
            rsrt = null;
            pstmtrt = null;
        }
        if (rt == null)
            throw new XFireFault("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'";
        /** 2014-11-05 Carlos Parada Change for ReadOnly SQL Access */
        //sql = role.addAccessSQL(sql, table.getTableName(), true, true);
        sql = role.addAccessSQL(sql, table.getTableName(), true, false);
        /** End Carlos Parada */
        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 XFireFault(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 XFireFault(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;
}
Also used : MColumn(org.compiere.model.MColumn) ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) DataSet(pl.x3E.adInterface.DataSet) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) MRole(org.compiere.model.MRole) WindowTabData(pl.x3E.adInterface.WindowTabData) ArrayList(java.util.ArrayList) ModelGetList(pl.x3E.adInterface.ModelGetList) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) MRefTable(org.compiere.model.MRefTable) SQLException(java.sql.SQLException) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) X_AD_Reference(org.compiere.model.X_AD_Reference) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ResultSet(java.sql.ResultSet)

Aggregations

XFireFault (org.codehaus.xfire.fault.XFireFault)8 QName (javax.xml.namespace.QName)6 Properties (java.util.Properties)5 MTable (org.compiere.model.MTable)5 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)5 DataField (pl.x3E.adInterface.DataField)5 DataRow (pl.x3E.adInterface.DataRow)5 SQLException (java.sql.SQLException)4 PO (org.compiere.model.PO)4 POInfo (org.compiere.model.POInfo)4 ModelCRUD (pl.x3E.adInterface.ModelCRUD)4 DataSet (pl.x3E.adInterface.DataSet)3 WindowTabData (pl.x3E.adInterface.WindowTabData)3 WindowTabDataDocument (pl.x3E.adInterface.WindowTabDataDocument)3 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 MRole (org.compiere.model.MRole)2 Trx (org.compiere.util.Trx)2