Search in sources :

Example 1 with DataField

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

the class ModelADServiceImpl method queryData.

public WindowTabDataDocument queryData(ModelCRUDRequestDocument req) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        CompiereService m_cs = getCompiereService();
        WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
        WindowTabData resp = ret.addNewWindowTabData();
        ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
        String serviceType = modelCRUD.getServiceType();
        ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
        String err = login(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.getCtx();
        String tableName = modelCRUD.getTableName();
        Map<String, Object> reqCtx = getRequestCtx();
        MWebServiceType m_webservicetype = getWebServiceType();
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("queryData"));
        int roleid = reqlogin.getRoleID();
        MRole role = MRole.get(ctx, roleid);
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelQueryData");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_queryData");
        StringBuilder sqlBuilder = new StringBuilder(role.addAccessSQL("SELECT * FROM " + tableName, tableName, true, MRole.SQL_RO));
        ArrayList<Object> sqlParaList = new ArrayList<Object>();
        PO holderPo = table.getPO(0, trxName);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        if (modelCRUD.getDataRow() != null) {
            DataRow dr = modelCRUD.getDataRow();
            DataField[] fields = dr.getFieldArray();
            StandardResponseDocument stdRet = StandardResponseDocument.Factory.newInstance();
            StandardResponse stdResp = stdRet.addNewStandardResponse();
            StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, holderPo, fields, trx, reqCtx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            retResp = scanFields(fields, m_webservicetype, holderPo, poinfo, trx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            for (DataField field : modelCRUD.getDataRow().getFieldArray()) {
                if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
                    // Jan Thielemann Solution for query using the sentence like
                    X_WS_WebServiceFieldInput inputField = m_webservicetype.getFieldInput(field.getColumn());
                    I_AD_Column col = inputField.getAD_Column();
                    String sqlType = DisplayType.getSQLDataType(col.getAD_Reference_ID(), col.getColumnName(), col.getFieldLength());
                    if (sqlType.contains("CHAR"))
                        sqlBuilder.append(" AND ").append(field.getColumn()).append(" LIKE ?");
                    else
                        sqlBuilder.append(" AND ").append(field.getColumn()).append("=?");
                    sqlParaList.add(holderPo.get_Value(field.getColumn()));
                // End Jan Thielemann Solution for query using the sentence like
                } else if (m_webservicetype.getFieldInput(field.getColumn()) == null) {
                    // If not even ctx variable column
                    throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed", new QName("queryData"));
                }
            }
        }
        if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0) {
            String sql = parseSQL(" WHERE " + modelCRUD.getFilter(), sqlParaList, holderPo, poinfo, reqCtx);
            sqlBuilder.append(" AND ").append(sql.substring(6));
        }
        int cnt = 0;
        int rowCnt = 0;
        int offset = modelCRUD.getOffset();
        int limit = modelCRUD.getLimit();
        PreparedStatement pstmtquery = null;
        ResultSet rsquery = null;
        try {
            pstmtquery = DB.prepareStatement(sqlBuilder.toString(), trxName);
            DB.setParameters(pstmtquery, sqlParaList);
            rsquery = pstmtquery.executeQuery();
            // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop
            DataSet ds = resp.addNewDataSet();
            while (rsquery.next()) {
                cnt++;
                if ((offset >= cnt) || (limit > 0 && offset + limit < cnt))
                    continue;
                rowCnt++;
                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 (rsquery.getObject(columnName) instanceof byte[])
                            dfid.setVal(new String(Base64.encodeBase64(rsquery.getBytes(columnName))));
                        else
                            dfid.setVal(rsquery.getString(columnName));
                    }
                }
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            throw new IdempiereServiceFault(e);
        } finally {
            DB.close(rsquery, pstmtquery);
            rsquery = null;
            pstmtquery = null;
        }
        resp.setSuccess(true);
        resp.setRowCount(rowCnt);
        resp.setNumRows(rowCnt);
        resp.setTotalRows(cnt);
        resp.setStartRow(offset);
        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) DataSet(org.idempiere.adInterface.x10.DataSet) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) ResultSet(java.sql.ResultSet) 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) QName(javax.xml.namespace.QName) I_AD_Column(org.compiere.model.I_AD_Column) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) PreparedStatement(java.sql.PreparedStatement) 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 2 with DataField

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

the class Process method runProcess.

/**
 ************************************************************************
 * 	Run process
 *	@param m_cs
 *  @param req
 *  @param requestCtx
 *  @param trxName
 *	@return {@link RunProcessResponseDocument}
 */
public static RunProcessResponseDocument runProcess(CompiereService m_cs, RunProcessDocument req, Map<String, Object> requestCtx, String trxName) {
    RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
    RunProcessResponse r = res.addNewRunProcessResponse();
    RunProcess rp = req.getRunProcess();
    int AD_Menu_ID = rp.getADMenuID();
    int AD_Process_ID = rp.getADProcessID();
    int m_record_id = rp.getADRecordID();
    MProcess process = null;
    if (AD_Menu_ID <= 0 && AD_Process_ID > 0)
        process = MProcess.get(m_cs.getCtx(), AD_Process_ID);
    else if (AD_Menu_ID > 0 && AD_Process_ID <= 0)
        process = MProcess.getFromMenu(m_cs.getCtx(), AD_Menu_ID);
    if (process == null) {
        r.setError("Process not found");
        r.setIsError(true);
        return res;
    }
    // Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
    String docAction = rp.getDocAction();
    if (docAction != null && docAction.length() > 0) {
        // - the process must be a workflow document
        if (process.getAD_Workflow_ID() > 0) {
            MWorkflow wf = MWorkflow.get(m_cs.getCtx(), process.getAD_Workflow_ID());
            if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
                // - get the table associated with the workflow document
                // - set DocAction in such table
                // get the PO for the tablename and record ID
                MTable table = MTable.get(m_cs.getCtx(), wf.getAD_Table_ID());
                if (table != null) {
                    PO po = table.getPO(m_record_id, null);
                    if (po != null) {
                        po.set_ValueOfColumn("DocAction", docAction);
                        po.saveEx();
                    }
                }
            }
        }
    }
    // Create Process Instance
    MPInstance pInstance = null;
    try {
        pInstance = fillParameter(m_cs, rp.getParamValues(), process, requestCtx);
    } catch (Exception ex) {
        r.setError(ex.getMessage());
        r.setIsError(true);
        return res;
    }
    DataField[] fields = rp.getParamValues().getFieldArray();
    for (DataField field : fields) {
        if ("AD_Record_ID".equals(field.getColumn())) {
            Object value = null;
            String s = field.getVal();
            if (requestCtx != null && !Util.isEmpty(s) && s.charAt(0) == '@') {
                value = ModelADServiceImpl.parseVariable(m_cs, requestCtx, field.getColumn(), s);
                if (value != null) {
                    if (value instanceof Number) {
                        m_record_id = ((Number) value).intValue();
                    } else {
                        try {
                            m_record_id = Integer.parseInt(value.toString());
                        } catch (Exception e) {
                        }
                    }
                }
            } else if (!Util.isEmpty(s)) {
                try {
                    m_record_id = Integer.parseInt(s);
                } catch (Exception e) {
                }
            }
        }
    }
    if (m_record_id > 0) {
        pInstance.setRecord_ID(m_record_id);
        pInstance.saveEx();
    }
    // 
    ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID());
    pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getCtx()));
    pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getCtx()));
    pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
    if (m_record_id > 0)
        pi.setRecord_ID(m_record_id);
    ProcessInfoParameter[] parameters = pi.getParameter();
    if (parameters == null) {
        ProcessInfoUtil.setParameterFromDB(pi);
        parameters = pi.getParameter();
    }
    for (DataField field : fields) {
        if (isDataURI(field.getVal())) {
            for (ProcessInfoParameter param : parameters) {
                if (param.getParameterName().equals(field.getColumn())) {
                    String data = field.getVal().substring(field.getVal().indexOf(";base64,") + ";base64,".length());
                    param.setParameter(data);
                    break;
                }
            }
        }
    }
    boolean processOK = false;
    boolean jasperreport = (process != null && (process.getJasperReport() != null || (process.getClassname() != null && process.getClassname().indexOf(ProcessUtil.JASPER_STARTER_CLASS) >= 0)));
    if (jasperreport) {
        processOK = true;
    }
    // Start
    if (process.isWorkflow()) {
        try {
            int AD_Workflow_ID = process.getAD_Workflow_ID();
            MWorkflow wf = MWorkflow.get(Env.getCtx(), AD_Workflow_ID);
            // may return null
            MWFProcess wfProcess = wf.startWait(pi);
            if (wfProcess != null) {
                // wynik
                r.setSummary(pi.getSummary());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(false);
                return res;
            }
        } catch (Exception ex) {
            r.setError(ex.getMessage());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            return res;
        }
    }
    if (process.isJavaProcess() && !jasperreport) {
        Trx trx = trxName == null ? Trx.get(Trx.createTrxName("WebPrc"), true) : Trx.get(trxName, true);
        if (trxName == null)
            trx.setDisplayName(Process.class.getName() + "_runProcess");
        try {
            processOK = process.processIt(pi, trx, false);
            if (trxName == null && processOK)
                trx.commit();
            else if (trxName == null && !processOK)
                trx.rollback();
        } catch (Throwable t) {
            trx.rollback();
        } finally {
            if (trxName == null)
                trx.close();
        }
        if (!processOK || pi.isError()) {
            r.setSummary(pi.getSummary());
            r.setError(pi.getSummary());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            processOK = false;
        } else {
            try {
                if (pi.getExportFile() != null) {
                    r.setData(java.nio.file.Files.readAllBytes(pi.getExportFile().toPath()));
                    r.setReportFormat(pi.getExportFileExtension());
                }
                r.setSummary(pi.getSummary());
                r.setError(pi.getSummary());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(false);
            } catch (Exception e) {
                r.setError("Cannot get the export file:" + e.getMessage());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(true);
                return res;
            }
        }
    }
    // Report
    if ((process.isReport() || jasperreport)) {
        pi.setReportingProcess(true);
        r.setIsReport(true);
        ReportEngine re = null;
        if (!jasperreport)
            re = start(pi);
        if (re == null && !jasperreport) {
            ;
        } else {
            try {
                boolean ok = false;
                String file_type = "pdf";
                if (!jasperreport) {
                    MPrintFormat pf = re.getPrintFormat();
                    if (pf.isTableBased()) {
                        CharArrayWriter wr = new CharArrayWriter();
                        ok = ReportEngineEx.createEXCEL_HTML_wr(re, m_cs.getCtx(), wr, false, re.getPrintFormat().getLanguage());
                        file_type = "html";
                        String data = wr.toString();
                        if (data != null)
                            r.setData(data.getBytes());
                        r.setReportFormat(file_type);
                    } else {
                        byte[] dat = re.createPDFData();
                        file_type = "pdf";
                        r.setData(dat);
                        r.setReportFormat(file_type);
                    }
                    ok = true;
                } else {
                    Trx trx = trxName == null ? Trx.get(Trx.createTrxName("WebPrc"), true) : Trx.get(trxName, true);
                    pi.setPrintPreview(false);
                    pi.setIsBatch(true);
                    ProcessUtil.startJavaProcess(Env.getCtx(), pi, trx, true, null);
                    file_type = "pdf";
                    r.setData(java.nio.file.Files.readAllBytes(pi.getPDFReport().toPath()));
                    r.setReportFormat(file_type);
                    ok = true;
                }
                if (ok) {
                    // Marker that Process is OK
                    m_cs.getCtx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                } else {
                    r.setError("Cannot create report");
                    r.setLogInfo(pi.getLogInfo(true));
                    r.setIsError(true);
                    return res;
                }
            } catch (Exception e) {
                r.setError("Cannot create report:" + e.getMessage());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(true);
                return res;
            // ,
            }
        }
    }
    return res;
}
Also used : MWFProcess(org.compiere.wf.MWFProcess) RunProcess(org.idempiere.adInterface.x10.RunProcess) MWFProcess(org.compiere.wf.MWFProcess) MProcess(org.compiere.model.MProcess) RunProcessResponse(org.idempiere.adInterface.x10.RunProcessResponse) CharArrayWriter(java.io.CharArrayWriter) RunProcess(org.idempiere.adInterface.x10.RunProcess) Trx(org.compiere.util.Trx) MProcess(org.compiere.model.MProcess) MWorkflow(org.compiere.wf.MWorkflow) ProcessInfo(org.compiere.process.ProcessInfo) ParseException(java.text.ParseException) ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) RunProcessResponseDocument(org.idempiere.adInterface.x10.RunProcessResponseDocument) PO(org.compiere.model.PO)

Example 3 with DataField

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

the class QueryDataLookup method getData.

/* (non-Javadoc)
	 * @see org.compiere.model.Lookup#getData(boolean, boolean, boolean, boolean, boolean)
	 */
@Override
public ArrayList<Object> getData(boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary, boolean shortlist) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    SOAPConnectionFactory cf;
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        dataMap = new LinkedHashMap<Integer, KeyNamePair>();
        cf = SOAPConnectionFactory.newInstance();
        SOAPConnection conn = cf.createConnection();
        // Create a SOAPMessage instance
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();
        // Create a SOAP envelope and body
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope env = part.getEnvelope();
        SOAPBody body = env.getBody();
        ModelCRUDRequestDocument crudDocument = ModelCRUDRequestDocument.Factory.newInstance();
        ModelCRUDRequest crudRequest = crudDocument.addNewModelCRUDRequest();
        crudRequest.setADLoginRequest(login);
        ModelCRUD crud = crudRequest.addNewModelCRUD();
        crud.setRecordID(0);
        crud.setFilter(filter);
        crud.setAction(ModelCRUD.Action.READ);
        crud.setServiceType(serviceType);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element element = document.createElementNS("http://idempiere.org/ADInterface/1_0", "queryData");
        Node domNode = document.importNode(crudDocument.getDomNode().getFirstChild(), true);
        document.appendChild(element);
        element.appendChild(domNode);
        body.addDocument(document);
        // Invoke the service endpoint
        URL endpoint = new URL(endPoint);
        SOAPMessage responseMsg = null;
        try {
            responseMsg = conn.call(message, endpoint);
        } finally {
            conn.close();
        }
        if (responseMsg != null && responseMsg.getSOAPBody() != null) {
            if (responseMsg.getSOAPBody().hasFault()) {
                throw new RuntimeException(responseMsg.getSOAPBody().getFault().getFaultString());
            }
            WindowTabDataDocument responseDoc = WindowTabDataDocument.Factory.parse(responseMsg.getSOAPBody().getFirstChild().getFirstChild());
            WindowTabData windowTabData = responseDoc.getWindowTabData();
            if (windowTabData.isSetError()) {
                throw new RuntimeException(windowTabData.getError());
            }
            DataSet dataset = windowTabData.getDataSet();
            DataRow[] dataRows = dataset.getDataRowArray();
            for (DataRow dataRow : dataRows) {
                DataField[] dataFields = dataRow.getFieldArray();
                String key = null;
                String display = null;
                for (DataField dataField : dataFields) {
                    if (dataField.getColumn().equals(keyColumn)) {
                        key = dataField.getVal();
                    } else if (dataField.getColumn().equals(displayColumn)) {
                        display = dataField.getVal();
                    }
                }
                if (key != null && display != null) {
                    Integer id = Integer.valueOf(key);
                    dataMap.put(id, new KeyNamePair(id, display));
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e.getLocalizedMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    return new ArrayList<Object>(dataMap.values());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DataSet(org.idempiere.adInterface.x10.DataSet) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) Document(org.w3c.dom.Document) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) SOAPMessage(javax.xml.soap.SOAPMessage) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) DataRow(org.idempiere.adInterface.x10.DataRow) URL(java.net.URL) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) SOAPPart(javax.xml.soap.SOAPPart) SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) SOAPBody(javax.xml.soap.SOAPBody) ModelCRUDRequest(org.idempiere.adInterface.x10.ModelCRUDRequest) DataField(org.idempiere.adInterface.x10.DataField) DocumentBuilder(javax.xml.parsers.DocumentBuilder) KeyNamePair(org.compiere.util.KeyNamePair)

Example 4 with DataField

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

the class CompositeServiceImpl method rollbackAndSetError.

/**
 * @param ctx
 * @param crud
 */
/*
	public void resolveContextCRUD(Properties ctx, ModelCRUD crud) {
		DataField fields[] = crud.getDataRow().getFieldArray();
		for (DataField field : fields) {
			String val = field.getVal();
			if (val != null && val.startsWith("#")) {
				// Replace value from context variables
				String key = val.substring(1);
				val = (String) ctx.get(key);
				field.setVal(val);
			}
		}
	}*/
/**
 * Rollback and set error on response
 * @param trx
 * @param compResp
 * @param respAggregator
 * @param string
 */
protected void rollbackAndSetError(Trx trx, CompositeResponse compResp, ArrayList<StandardResponse> respAggregator, String string) {
    if (respAggregator == null) {
        StandardResponse resp = compResp.addNewStandardResponse();
        resp.setError(string);
        resp.setIsError(true);
    } else {
        int ind = 0;
        StandardResponse[] orgArr = compResp.getStandardResponseArray();
        StandardResponse[] respArr = new StandardResponse[orgArr.length + respAggregator.size()];
        for (StandardResponse resp : orgArr) {
            respArr[ind++] = resp;
        }
        // Set all response as Failed
        for (StandardResponse resp : respAggregator) {
            resp.setIsRolledBack(true);
            respArr[ind++] = resp;
        }
        if (string != null && respAggregator.size() > 0) {
            StandardResponse resp = respAggregator.get(respAggregator.size() - 1);
            resp.setError(string);
            resp.setIsError(true);
        }
        compResp.setStandardResponseArray(respArr);
        respAggregator.clear();
    }
    trx.rollback();
    trx.close();
}
Also used : StandardResponse(org.idempiere.adInterface.x10.StandardResponse)

Example 5 with DataField

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

the class ModelADServiceImpl method readData.

// updateData
public WindowTabDataDocument readData(ModelCRUDRequestDocument req) {
    try {
        getCompiereService().connect();
        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 = login(reqlogin, webServiceName, "readData", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            return ret;
        }
        // Validate parameters vs service type
        try {
            validateCRUD(modelCRUD);
        } catch (IdempiereServiceFault e) {
            resp.setError(e.getMessage());
            return ret;
        }
        CompiereService m_cs = getCompiereService();
        MWebServiceType m_webservicetype = getWebServiceType();
        // start a trx
        String trxName = localTrxName;
        Properties ctx = m_cs.getCtx();
        String tableName = modelCRUD.getTableName();
        String recordIDVar = modelCRUD.getRecordIDVariable();
        int recordID = modelCRUD.getRecordID();
        if (recordIDVar != null && recordIDVar.startsWith("@")) {
            Integer retVal = (Integer) parseVariable(recordIDVar, null, null, getRequestCtx());
            if (retVal == null) {
                resp.setError("Cannot resolve variable: " + recordIDVar);
                return ret;
            }
            recordID = retVal;
        }
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("readData"));
        PO po = table.getPO(recordID, trxName);
        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) {
                    if (po.get_Value(i) instanceof byte[]) {
                        dfid.setVal(new String(Base64.encodeBase64((byte[]) po.get_Value(i))));
                    } else if (po.get_Value(i) instanceof Boolean) {
                        dfid.setVal((Boolean) po.get_Value(i) ? "Y" : "N");
                    } else {
                        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;
    } finally {
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) POInfo(org.compiere.model.POInfo) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) PO(org.compiere.model.PO)

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