Search in sources :

Example 1 with DataField

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

the class ADLookup method getLookupSearchValues.

public void getLookupSearchValues(DataRow adr, DataSet ds, Properties ctx, int windowNo) {
    //String whereClause = getWhere(adr);		
    String whereClause = getWhereClause(m_columnName, adr);
    String finalSQL = "";
    IsQueryJoin = false;
    String mode = "normal";
    for (int i = 0; i < adr.sizeOfFieldArray(); i++) {
        DataField f = adr.getFieldArray(i);
        if ("mode".equalsIgnoreCase(f.getColumn()))
            mode = f.getVal();
    }
    ADInfo info = null;
    if (m_columnName.equals("C_BPartner_ID")) {
        //finalSQL = getBuisnessPartnerSQL(whereClause, adr);
        info = new InfoBPartner(adr, whereClause);
    } else if (m_columnName.equals("M_Product_ID")) {
        info = new InfoProduct(adr, whereClause, ctx, windowNo);
    //finalSQL = getProductSQL(whereClause);	
    } else if (m_columnName.equals("C_Order_ID")) {
    //finalSQL = getOrderAccessSQL(whereClause);
    }
    if (finalSQL.equals("")) {
    //finalSQL = getDirectAccessSQL(whereClause);
    }
    //Sprawdzam czy przy wykonaniu FinalSql zwr�ci mi 0, 1 lub wiele wierszy
    //Je�eli zwr�ci mi 0 wierszy to ko�cz�
    //Je�eli zwr�ci mi 1 wiersz to ko�cowy wynik b�dzie kwerend� normaln� (w przypadku join�w, np.: bp zostanie wykonana alternatywna kwerenda bez join�w)
    //Je�eli zwr�ci mi n wierszy to zwracam je
    int id = 0;
    log.info("Starting execution to base");
    try {
        /*
			PreparedStatement pstmt = DB.prepareStatement( finalSQL );
			info.setParameters( pstmt, true);
			ResultSet rs = pstmt.executeQuery();
			//Wykonuje zapytanie do bazy z "normalnym" sql i sprawdzam ile, mam wierszy wyniku
			int ile = 0;
			while (rs.next())
			{
			 ile = ile+1;				
			}*/
        int ile = 0;
        finalSQL = info.getSQLCount();
        PreparedStatement pstmt = DB.prepareStatement(finalSQL, null);
        info.setParameters(pstmt, true);
        ResultSet rs = pstmt.executeQuery();
        if (rs.next())
            ile = rs.getInt(1);
        rs.close();
        pstmt.close();
        System.out.println("Znalaz�em " + ile + " wierszy / rekord�w");
        //w kliencie spowoduje to wyswietlenie pustego okna lookUp
        if (ile == 0) {
            System.out.println("Nie znalaz�em rekord�w. W kliencie zostanie wy�wietlone okno LookUp'a bez rekord�w.");
        }
        //join�w
        if ((ile == 1)) {
            System.out.println("Znalaz�em 1 rekord wi�c szukam dla bez join. W kliencie zostanie automatycznie uzupe�niona warto�c");
            IsQueryJoin = false;
        }
        //w oknie LookUp'a
        if (ile > 1) {
            System.out.println("Znalaz�em wi�cej ni� 1 rekord wi�c szukam dla whereClause i z joinami. W kliencie zostanie wy�wietlone LookUpWindow z przefiltrowanymi rekordami.");
            IsQueryJoin = true;
        }
        ds = getResult(info, ds, ile, mode);
    } catch (Exception e) {
        log.log(Level.SEVERE, finalSQL, e);
        id = -2;
    }
    //	No (unique) result
    if (id <= 0) {
        if (id == 0)
            log.fine("Not Found - " + finalSQL);
        else
            log.fine("Not Unique - " + finalSQL);
    //m_value = null;	// force re-display
    //actionButton(m_text.getText());
    //return r;
    }
    log.fine("Unique ID=" + id);
}
Also used : DataField(pl.x3E.adInterface.DataField) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 2 with DataField

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

the class ADLookup method getResult.

private DataSet getResult(com._3e.ADInterface.ADInfo info, DataSet ds, int count, String mode) {
    if ("count".equals(mode) && count > 1) {
        DataRow dr = ds.addNewDataRow();
        DataField df = dr.addNewField();
        df.setVal("" + count);
        df.setColumn("__count");
        df.setType("string");
        return ds;
    }
    try {
        PreparedStatement pstmt = DB.prepareStatement(info.getSQL());
        info.setParameters(pstmt, false);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            DataRow dr = ds.addNewDataRow();
            DataField df = null;
            //DataField df = dr.addNewField();
            DataRow cols = info.getColumns();
            for (int i = 0; i < cols.sizeOfFieldArray(); i++) {
                df = dr.addNewField();
                DataField f = cols.getFieldArray(i);
                //if ("string".equalsIgnoreCase(f.getType())) {
                {
                    df.setVal(rs.getString(i + 1));
                    df.setColumn(f.getColumn());
                    df.setType(f.getType());
                    df.setLval(f.getLval());
                }
            }
        }
        rs.close();
        pstmt.close();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return ds;
}
Also used : DataField(pl.x3E.adInterface.DataField) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DataRow(pl.x3E.adInterface.DataRow) SQLException(java.sql.SQLException)

Example 3 with DataField

use of pl.x3E.adInterface.DataField 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 4 with DataField

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

the class Process method fillParameter.

//	createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap fmap = new HashMap();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
    //
    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;
        Object ob = fmap.get(key);
        if (ob != null)
            valueString = ob.toString();
        String valueString2 = null;
        if (pPara.isRange()) {
            ob = fmap.get(key + "_2");
            if (ob != null)
                valueString2 = ob.toString();
        }
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.List == 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);
                    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 (displayType == DisplayType.DateTime)
                        d = m_cs.dateFormat.parse(value.toString());
                    else
                        // TODO: datetime
                        d = m_cs.dateFormat.parse(value.toString());
                    //d = m_cs.dateTimeFormat.parse(value.toString());
                    Timestamp ts = null;
                    ts = new Timestamp(d.getTime());
                    iPara.setP_Date(ts);
                    if (pPara.isRange()) {
                        if (displayType == DisplayType.DateTime)
                            d = m_cs.dateFormat.parse(valueString2);
                        else //d = m_cs.dateTimeFormat.parse(valueString2);
                        {
                            if (valueString2 == null || valueString2.length() == 0)
                                d = new java.util.Date();
                            else
                                //TODO: datetime
                                d = m_cs.dateFormat.parse(valueString2);
                        }
                        ts = new Timestamp(d.getTime());
                        iPara.setP_Date_To(ts);
                    }
                    log.fine("fillParameter - " + 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.save();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    //	instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.save();
    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) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(pl.x3E.adInterface.DataField) Lookup(org.compiere.model.Lookup)

Example 5 with DataField

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

Aggregations

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