Search in sources :

Example 1 with DataSet

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

the class ADServiceImpl method getWindowTabData.

public WindowTabDataDocument getWindowTabData(WindowTabDataReqDocument reqd) throws XFireFault {
    authenticate(webServiceName, "getWindowTabData");
    WindowTabDataReq req = reqd.getWindowTabDataReq();
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, req.getWindowNo(), false, 0, false, 0);
    if (ws == null) {
        GridWindowVO wo = getWindowVO(req.getWindowNo(), req.getADWindowID(), req.getADMenuID());
        ws = new WWindowStatus(wo);
        WindowStatusMap.put(new Integer(req.getWindowNo()), ws);
        //!!!!!!!!!!
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.curTab.setSingleRow(true);
    }
    if (ws.curTab.getTabNo() != req.getPrevTabNo()) {
        ws.curTab.removeDataStatusListener(ws.ads);
        ws.curTab = ws.mWindow.getTab(req.getPrevTabNo());
        // false
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.updateRecIDMap();
    }
    /*
    	if (ws.curTab.getCurrentRow() != req.getPrevRecNo())  
    	{
    		if (req.getPrevRecNo() >=0)
    			ws.curTab.navigate( req.getPrevRecNo() );     		
    	}
    	*/
    // we assume that it RecordID
    int prevRecNo = ws.getRowNoFromRecordID(req.getPrevRecNo());
    if (ws.curTab.getCurrentRow() != prevRecNo) {
        if (prevRecNo >= 0)
            ws.curTab.navigate(prevRecNo);
    }
    WWindowStatus.changeTabIfNeeded(ws, req.getTabNo());
    if (req.getGetData()) {
        if (req.getFromZoom()) {
            WWindowStatus ws2 = WWindowStatus.get(WindowStatusMap, req.getFromZoomWindowID(), true, req.getFromZoomTabID(), true, req.getFromZoomRowID());
            System.out.println(ws2.curTab.getTableName());
            GridField field = ws2.curTab.getField(req.getFromZoomColumnName());
            ws2 = null;
            if (field == null)
                return null;
            MLookup lookup = (MLookup) field.getLookup();
            if (lookup == null)
                return null;
            //
            MQuery zoomQuery = lookup.getZoomQuery();
            Object value = field.getValue();
            if (value == null) {
                value = req.getFromZoomColumnValue();
            }
            //	If not already exist or exact value
            if (zoomQuery == null || value != null) {
                //	ColumnName might be changed in GridTab.validateQuery
                zoomQuery = new MQuery();
                zoomQuery.addRestriction(req.getFromZoomColumnName(), MQuery.EQUAL, value);
            }
            ws.curTab.setQuery(zoomQuery);
            //ws.curTab.query(ws.mWindow.isTransaction());
            // ADEMPIERE/COMPIERE
            // adempiere
            ws.curTab.query(false, 0, 0);
        //ws.curTab.query(false, 0); // compiere
        } else {
            DataRow findDR = req.getFindCriteria();
            MQuery currentQuery = ws.curTab.getQuery();
            MQuery newQuery = createQuery(ws.curTab.getTableName(), findDR);
            if (findDR.getFieldArray().length > 0) {
                //(!currentQuery.getWhereClause().equals( newQuery.getWhereClause() )) { // change the query for zak�adki
                ws.curTab.setQuery(newQuery);
                //ws.curTab.query(ws.mWindow.isTransaction());
                //ADEMPIERE/COMPIERE
                // adempiere
                ws.curTab.query(false, 0, 0);
            //ws.curTab.query(false, 0); // compiere
            }
        }
        int rc = 0;
        if (req.getRowCount() > 0)
            rc = req.getRowCount();
        else
            rc = ws.curTab.getRowCount();
        int initRowNo = 0;
        if (req.getRowStart() > 0)
            initRowNo = req.getRowStart();
        //ok
        int lastRow = Math.min(rc, initRowNo + MAX_ROWS);
        //initRowNo + 5; // only for testing
        wd.setNumRows(lastRow);
        //lastRow += initRowNo;
        // ok
        wd.setTotalRows(ws.curTab.getRowCount());
        //wd.setTotalRows( 5 ); // only for testing
        wd.setStartRow(initRowNo);
        Map<Integer, Integer> RecordIDMap = ws.getRecordIDMap();
        try {
            RecordIDMap.clear();
            for (int lineNo = initRowNo; lineNo < lastRow; lineNo++) {
                ws.curTab.navigate(lineNo);
                int recID = ws.curTab.getRecord_ID();
                RecordIDMap.put(recID, lineNo);
                DataRow dr = ds.addNewDataRow();
                //System.out.println("row "+lineNo);
                fillDataRow(dr, ws, false, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        ;
        if (lastRow <= ws.curTab.getRowCount()) {
            //last row
            ws.updateRecIDMap();
        }
    }
    return ret;
}
Also used : DataSet(pl.x3E.adInterface.DataSet) MLookup(org.compiere.model.MLookup) WindowTabData(pl.x3E.adInterface.WindowTabData) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) DataRow(pl.x3E.adInterface.DataRow) TransformerException(javax.xml.transform.TransformerException) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) WindowTabDataReq(pl.x3E.adInterface.WindowTabDataReq) GridWindowVO(org.compiere.model.GridWindowVO)

Example 2 with DataSet

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

the class ADServiceImpl method getLookupData.

public WindowTabDataDocument getLookupData(int WindowNo, int TabNo, int RowNo, String columnName) throws XFireFault {
    authenticate(webServiceName, "getLookupData");
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, WindowNo, true, TabNo, true, RowNo);
    if (ws != null) {
        DataRow dr = ds.addNewDataRow();
        DataField df = dr.addNewField();
        GridField field = ws.curTab.getField(columnName);
        Lookup lookup = field.getLookup();
        df.setColumn(field.getColumnName());
        String lookupValue = null;
        if (field.getValue() != null)
            lookupValue = lookup.getDisplay(field.getValue());
        df.setLval(lookupValue);
        if (field.getValue() != null)
            df.setVal(field.getValue().toString());
        LookupValues lvs = df.addNewLookup();
        ADLookup.fillLookupValues(lvs, lookup, field);
    }
    return ret;
}
Also used : WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) DataField(pl.x3E.adInterface.DataField) DataSet(pl.x3E.adInterface.DataSet) WindowTabData(pl.x3E.adInterface.WindowTabData) Lookup(org.compiere.model.Lookup) MLookup(org.compiere.model.MLookup) GridField(org.compiere.model.GridField) LookupValues(pl.x3E.adInterface.LookupValues) DataRow(pl.x3E.adInterface.DataRow)

Example 3 with DataSet

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

the class ADServiceImpl method getDataRow.

public WindowTabDataDocument getDataRow(int WindowNo, int TabNo, int RowNo) throws XFireFault {
    authenticate(webServiceName, "getDataRow");
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, WindowNo, true, TabNo, true, RowNo);
    if (ws != null) {
        DataRow dr = ds.addNewDataRow();
        fillDataRow(dr, ws, true, false);
        if (ws.ads.m_is_error) {
            wd.setError(ws.ads.m_error_message);
            wd.setErrorInfo(ws.ads.m_error_info);
        }
        wd.setStatus(ws.ads.m_status_data);
        wd.setStatusError(ws.ads.m_is_status_error);
    }
    return ret;
}
Also used : WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) DataSet(pl.x3E.adInterface.DataSet) WindowTabData(pl.x3E.adInterface.WindowTabData) DataRow(pl.x3E.adInterface.DataRow)

Example 4 with DataSet

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

Example 5 with DataSet

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

Aggregations

DataSet (pl.x3E.adInterface.DataSet)13 WindowTabData (pl.x3E.adInterface.WindowTabData)13 WindowTabDataDocument (pl.x3E.adInterface.WindowTabDataDocument)13 DataRow (pl.x3E.adInterface.DataRow)12 DataField (pl.x3E.adInterface.DataField)6 Properties (java.util.Properties)3 QName (javax.xml.namespace.QName)3 XFireFault (org.codehaus.xfire.fault.XFireFault)3 GridField (org.compiere.model.GridField)3 MTable (org.compiere.model.MTable)3 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 MLookup (org.compiere.model.MLookup)2 MRole (org.compiere.model.MRole)2 PO (org.compiere.model.PO)2 POInfo (org.compiere.model.POInfo)2 ModelCRUD (pl.x3E.adInterface.ModelCRUD)2 ModelGetList (pl.x3E.adInterface.ModelGetList)2 BigDecimal (java.math.BigDecimal)1