Search in sources :

Example 1 with ModelCRUD

use of pl.x3E.adInterface.ModelCRUD 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 ModelCRUD

use of pl.x3E.adInterface.ModelCRUD in project adempiere by adempiere.

the class ModelADServiceImpl method deleteData.

// getList
public StandardResponseDocument deleteData(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, "deleteData", 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_modelDeleteData");
    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);
    if (!po.delete(false))
        return rollbackAndSetError(trx, resp, ret, true, "Cannot delete record " + recordID + " 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) MTable(org.compiere.model.MTable) StandardResponse(pl.x3E.adInterface.StandardResponse) ModelCRUD(pl.x3E.adInterface.ModelCRUD) Trx(org.compiere.util.Trx) Properties(java.util.Properties) StandardResponseDocument(pl.x3E.adInterface.StandardResponseDocument) PO(org.compiere.model.PO)

Example 3 with ModelCRUD

use of pl.x3E.adInterface.ModelCRUD 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 ModelCRUD

use of pl.x3E.adInterface.ModelCRUD in project adempiere by adempiere.

the class ModelADServiceImpl method readData.

// updateData
public WindowTabDataDocument readData(ModelCRUDRequestDocument req) throws XFireFault {
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData resp = ret.addNewWindowTabData();
    ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
    String serviceType = modelCRUD.getServiceType();
    int cnt = 0;
    ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
    String err = modelLogin(reqlogin, webServiceName, "readData", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        return ret;
    }
    // Validate parameters vs service type
    validateCRUD(modelCRUD);
    Properties ctx = m_cs.getM_ctx();
    String tableName = modelCRUD.getTableName();
    int recordID = modelCRUD.getRecordID();
    // get the PO for the tablename and record ID
    MTable table = MTable.get(ctx, tableName);
    if (table == null)
        throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("readData"));
    PO po = table.getPO(recordID, null);
    if (po == null) {
        resp.setSuccess(false);
        resp.setRowCount(cnt);
        resp.setNumRows(cnt);
        resp.setTotalRows(cnt);
        resp.setStartRow(0);
        return ret;
    }
    cnt = 1;
    POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
    DataSet ds = resp.addNewDataSet();
    DataRow dr = ds.addNewDataRow();
    for (int i = 0; i < poinfo.getColumnCount(); i++) {
        String columnName = poinfo.getColumnName(i);
        if (m_webservicetype.isOutputColumnNameAllowed(columnName)) {
            DataField dfid = dr.addNewField();
            dfid.setColumn(columnName);
            if (po.get_Value(i) != null)
                dfid.setVal(po.get_Value(i).toString());
            else
                dfid.setVal(null);
        }
    }
    resp.setSuccess(true);
    resp.setRowCount(cnt);
    resp.setNumRows(cnt);
    resp.setTotalRows(cnt);
    resp.setStartRow(1);
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) DataSet(pl.x3E.adInterface.DataSet) QName(javax.xml.namespace.QName) WindowTabData(pl.x3E.adInterface.WindowTabData) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) POInfo(org.compiere.model.POInfo) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) PO(org.compiere.model.PO)

Example 5 with ModelCRUD

use of pl.x3E.adInterface.ModelCRUD in project adempiere by adempiere.

the class ModelADServiceImpl method queryData.

public WindowTabDataDocument queryData(ModelCRUDRequestDocument req) throws XFireFault {
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData resp = ret.addNewWindowTabData();
    ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
    String serviceType = modelCRUD.getServiceType();
    /** 2014-12-04 Carlos Parada Add Support for Paginate Records */
    /** Current Page*/
    int currentPage = req.getModelCRUDRequest().getModelCRUD().getPageNo();
    /** Records per Page*/
    int m_RecByPage = MSysConfig.getIntValue("WS_RECORDS_BY_PAGE", 1);
    /** Quantity Pages*/
    int qtyPages = 0;
    log.info("Current Page " + currentPage);
    /** 2014-12-04 Carlos Parada */
    ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
    String err = modelLogin(reqlogin, webServiceName, "queryData", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        return ret;
    }
    // Validate parameters vs service type
    validateCRUD(modelCRUD);
    Properties ctx = m_cs.getM_ctx();
    String tableName = modelCRUD.getTableName();
    // get the PO for the tablename and record ID
    MTable table = MTable.get(ctx, tableName);
    if (table == null)
        throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("queryData"));
    int roleid = reqlogin.getRoleID();
    MRole role = new MRole(ctx, roleid, null);
    // 2014-12-04 Carlos Parada Replace ResultSet For Query  
    List<PO> records = null;
    String key = m_cs.getM_AD_User_ID() + "_" + serviceType;
    if (currentPage != 0)
        records = (List<PO>) s_cache.get(key);
    //"SELECT * FROM " + tableName;
    String sqlWhere = "";
    //sqlquery = role.addAccessSQL(sqlquery, tableName, true, true);
    for (DataField field : modelCRUD.getDataRow().getFieldList()) {
        if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
            sqlWhere += (sqlWhere.equals("") ? "" : " AND ") + field.getColumn() + "=?";
        } else {
            throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed", new QName("queryData"));
        }
    }
    if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0)
        sqlWhere += " AND " + modelCRUD.getFilter();
    POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
    int cnt = 0;
    try {
        if (records == null) {
            Query query = new Query(ctx, poinfo.getTableName(), sqlWhere, null);
            Object[] parameters = new Object[modelCRUD.getDataRow().getFieldList().size()];
            int p = 1;
            int i = 0;
            for (DataField field : modelCRUD.getDataRow().getFieldList()) {
                parameters[i] = field.getVal();
                i++;
            }
            if (parameters.length > 0)
                query.setParameters(parameters);
            records = query.setApplyAccessFilter(true).list();
        }
        // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop
        DataSet ds = resp.addNewDataSet();
        // Set Quantity of Pages
        if (records.size() != 0)
            qtyPages = new BigDecimal(records.size()).divide(new BigDecimal(m_RecByPage)).setScale(0, BigDecimal.ROUND_UP).intValue();
        int begin = 0, end = 0;
        begin = currentPage * m_RecByPage;
        end = (((currentPage + 1) * m_RecByPage) > records.size() ? records.size() : ((currentPage + 1) * m_RecByPage));
        for (int j = begin; j < end; j++) {
            PO record = records.get(j);
            cnt++;
            DataRow dr = ds.addNewDataRow();
            for (int i = 0; i < poinfo.getColumnCount(); i++) {
                String columnName = poinfo.getColumnName(i);
                if (m_webservicetype.isOutputColumnNameAllowed(columnName)) {
                    DataField dfid = dr.addNewField();
                    dfid.setColumn(columnName);
                    dfid.setLval(record.get_ValueAsString(columnName));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    // ignore this exception
    }
    resp.setSuccess(true);
    resp.setRowCount(cnt);
    resp.setNumRows(cnt);
    resp.setTotalRows(cnt);
    resp.setStartRow(1);
    resp.setQtyPages(qtyPages);
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) Query(org.compiere.model.Query) DataSet(pl.x3E.adInterface.DataSet) QName(javax.xml.namespace.QName) MRole(org.compiere.model.MRole) WindowTabData(pl.x3E.adInterface.WindowTabData) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) POInfo(org.compiere.model.POInfo) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) List(java.util.List) ModelGetList(pl.x3E.adInterface.ModelGetList) ArrayList(java.util.ArrayList) PO(org.compiere.model.PO)

Aggregations

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