Search in sources :

Example 1 with JCoTable

use of com.sap.conn.jco.JCoTable in project Clownfish by rawdog71.

the class SAPUtility method getSapExport.

/*
        getSapExport
        Übergibt die POST Parameter und ruft SAP RFC auf
        Setzt die Ergebnisse in eine Hashmap zur Ausgabe in Freemarker
    */
public static HashMap<String, HashMap> getSapExport(List<CfSitesaprfc> sitesaprfclist, HashMap<String, List> saprfcfunctionparamMap, List<JsonFormParameter> postmap, RPY_TABLE_READ rpytableread) {
    JCoTable functions_table = null;
    HashMap<String, HashMap> sapexport = new HashMap<>();
    for (CfSitesaprfc cfsitesaprfc : sitesaprfclist) {
        try {
            HashMap<String, Object> sapvalues = new HashMap<>();
            List<RfcFunctionParam> paramlist = saprfcfunctionparamMap.get(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction());
            // Setze die Import Parameter des SAP RFC mit den Werten aus den POST Parametern
            JCoFunction function = sapc.getDestination().getRepository().getFunction(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction());
            for (RfcFunctionParam rfcfunctionparam : paramlist) {
                if (rfcfunctionparam.getParamclass().compareToIgnoreCase("I") == 0) {
                    if (null != postmap) {
                        for (JsonFormParameter jfp : postmap) {
                            if (jfp.getName().compareToIgnoreCase(rfcfunctionparam.getParameter()) == 0) {
                                function.getImportParameterList().setValue(rfcfunctionparam.getParameter(), jfp.getValue());
                            }
                        }
                    }
                }
            }
            // SAP RFC ausführen
            function.execute(sapc.getDestination());
            HashMap<String, ArrayList> saptables = new HashMap<>();
            for (RfcFunctionParam rfcfunctionparam : paramlist) {
                String tablename = rfcfunctionparam.getTabname();
                String paramname = rfcfunctionparam.getParameter();
                if (rfcfunctionparam.getParamclass().compareToIgnoreCase("E") == 0) {
                    sapvalues.put(rfcfunctionparam.getParameter(), function.getExportParameterList().getString(rfcfunctionparam.getParameter()));
                }
                if (rfcfunctionparam.getParamclass().compareToIgnoreCase("T") == 0) {
                    ArrayList<HashMap> tablevalues = new ArrayList<>();
                    functions_table = function.getTableParameterList().getTable(paramname);
                    List<RpyTableRead> rpytablereadlist = rpytableread.getRpyTableReadList(tablename);
                    for (int i = 0; i < functions_table.getNumRows(); i++) {
                        HashMap<String, String> sapexportvalues = new HashMap<>();
                        functions_table.setRow(i);
                        for (RpyTableRead rpytablereadentry : rpytablereadlist) {
                            if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.CHAR) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.NUMC) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.UNIT) == 0)) {
                                String value = functions_table.getString(rpytablereadentry.getFieldname());
                                sapexportvalues.put(rpytablereadentry.getFieldname(), value);
                                continue;
                            }
                            if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.DATS) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.TIMS) == 0)) {
                                Date value = functions_table.getDate(rpytablereadentry.getFieldname());
                                String datum = "";
                                if (null != value) {
                                    if (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.DATS) == 0) {
                                        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
                                        datum = sdf.format(value);
                                    } else {
                                        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                                        datum = sdf.format(value);
                                    }
                                }
                                sapexportvalues.put(rpytablereadentry.getFieldname(), datum);
                                continue;
                            }
                            if (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.QUAN) == 0) {
                                double value = functions_table.getDouble(rpytablereadentry.getFieldname());
                                sapexportvalues.put(rpytablereadentry.getFieldname(), String.valueOf(value));
                                continue;
                            }
                            if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT1) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT2) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT4) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT8) == 0)) {
                                int value = functions_table.getInt(rpytablereadentry.getFieldname());
                                sapexportvalues.put(rpytablereadentry.getFieldname(), String.valueOf(value));
                            }
                        }
                        tablevalues.add(sapexportvalues);
                    }
                    saptables.put(paramname, tablevalues);
                }
            }
            sapvalues.put("table", saptables);
            sapexport.put(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction(), sapvalues);
        } catch (JCoException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    return sapexport;
}
Also used : JCoFunction(com.sap.conn.jco.JCoFunction) HashMap(java.util.HashMap) JsonFormParameter(io.clownfish.clownfish.beans.JsonFormParameter) ArrayList(java.util.ArrayList) Date(java.util.Date) CfSitesaprfc(io.clownfish.clownfish.dbentities.CfSitesaprfc) RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) JCoTable(com.sap.conn.jco.JCoTable) JCoException(com.sap.conn.jco.JCoException) SimpleDateFormat(java.text.SimpleDateFormat) RpyTableRead(io.clownfish.clownfish.sap.models.RpyTableRead)

Example 2 with JCoTable

use of com.sap.conn.jco.JCoTable in project bonita-connector-sap by bonitasoft.

the class SAPCallFunction method fillJCOTableParameterList.

@SuppressWarnings("unchecked")
private JCoParameterList fillJCOTableParameterList() throws ConnectorException {
    final JCoParameterList tableParameterList = function.getTableParameterList();
    final List<List<Object>> inputParameters = (List<List<Object>>) getInputParameter(INPUT_PARAMETERS);
    if (inputParameters != null) {
        final JCoParameterList inputParameterList = function.getImportParameterList();
        for (List<Object> column : inputParameters) {
            final String parameterType = (String) column.get(0);
            final String tableName = (String) column.get(1);
            final String parameterName = (String) column.get(2);
            final Object parameterValue = column.get(3);
            if (INPUT_STRUCTURE.equals(parameterType)) {
                if (inputParameterList == null) {
                    throw new ConnectorException("input_structure is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
                }
                final JCoStructure structure = inputParameterList.getStructure(tableName);
                if (structure == null) {
                    throw new ConnectorException("input_structure is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
                }
                structure.setValue(parameterName, parameterValue);
            } else if (INPUT_SINGLE.equals(parameterType)) {
                if (inputParameterList == null) {
                    throw new ConnectorException("input_single is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
                }
                inputParameterList.setValue(parameterName, parameterValue);
            } else {
                // INPUT_TABLE or TABLE_INPUT
                List<Object> list = new ArrayList<>();
                if (parameterValue instanceof List<?>) {
                    list.addAll((List<Object>) parameterValue);
                } else {
                    list.add(parameterValue);
                }
                int rowSize = list.size();
                JCoTable table = null;
                if (INPUT_TABLE.equals(parameterType)) {
                    if (inputParameterList == null) {
                        throw new ConnectorException("input_table is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
                    }
                    table = inputParameterList.getTable(tableName);
                } else if (TABLE_INPUT.equals(parameterType)) {
                    if (tableParameterList == null) {
                        throw new ConnectorException("table_input is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
                    }
                    table = tableParameterList.getTable(tableName);
                }
                if (table != null) {
                    table.firstRow();
                    for (int rowNb = 0; rowNb < rowSize; rowNb++) {
                        if (table.getNumRows() < (rowNb + 1)) {
                            table.appendRow();
                        }
                        table.setValue(parameterName, list.get(rowNb));
                        table.nextRow();
                    }
                }
            }
        }
    }
    return tableParameterList;
}
Also used : JCoStructure(com.sap.conn.jco.JCoStructure) ConnectorException(org.bonitasoft.engine.connector.ConnectorException) JCoTable(com.sap.conn.jco.JCoTable) ArrayList(java.util.ArrayList) JCoParameterList(com.sap.conn.jco.JCoParameterList) List(java.util.List) JCoParameterList(com.sap.conn.jco.JCoParameterList)

Example 3 with JCoTable

use of com.sap.conn.jco.JCoTable in project JavaClasses by genexuslabs.

the class EnterpriseConnect method getValue.

/*        ---   Get Return Values  ---           */
public void getValue(String parameterName, GXSimpleCollection[] value) {
    if (value.length != 0) {
        GXSimpleCollection col = value[0];
        col.clear();
        JCoTable tbl = function.getTableParameterList().getTable(parameterName);
        JSONArray jCol = new JSONArray();
        try {
            for (int i = 0; i < tbl.getNumRows(); i++) {
                JSONObject jRow = new JSONObject();
                tbl.setRow(i);
                for (JCoField field : tbl) {
                    if (field.getType() == JCoMetaData.TYPE_INT || (field.getType() == JCoMetaData.TYPE_NUM && field.getDecimals() == 0)) {
                        jRow.put(field.getName(), field.getLong());
                    } else if (field.getType() == JCoMetaData.TYPE_INT2 || field.getType() == JCoMetaData.TYPE_INT1 || field.getType() == JCoMetaData.TYPE_BYTE) {
                        jRow.put(field.getName(), field.getInt());
                    } else if (field.getType() == JCoMetaData.TYPE_NUM || field.getType() == JCoMetaData.TYPE_FLOAT || field.getType() == JCoMetaData.TYPE_BCD) {
                        jRow.put(field.getName(), field.getDouble());
                    } else {
                        jRow.put(field.getName(), field.getString());
                    }
                }
                jCol.put(jRow);
            }
            col.FromJSONObject(jCol);
        } catch (JSONException ex) {
            throw new RuntimeException(ex.toString());
        }
    }
}
Also used : JSONObject(json.org.json.JSONObject) JCoTable(com.sap.conn.jco.JCoTable) GXSimpleCollection(com.genexus.GXSimpleCollection) JSONArray(json.org.json.JSONArray) JSONException(json.org.json.JSONException) JCoField(com.sap.conn.jco.JCoField)

Example 4 with JCoTable

use of com.sap.conn.jco.JCoTable in project bonita-connector-sap by bonitasoft.

the class SAPCallFunction method retrieveTableVariableValue.

private Serializable retrieveTableVariableValue(final JCoParameterList tableParameterList, final JCoParameterList outputParameterList, final String parameterType, final String tableName, final String xpath) {
    Serializable variableValue;
    JCoTable table = null;
    if (OUTPUT_TABLE.equals(parameterType)) {
        table = outputParameterList.getTable(tableName);
    } else if (TABLE_OUTPUT.equals(parameterType)) {
        table = tableParameterList.getTable(tableName);
    }
    ArrayList<String> list = new ArrayList<>();
    if (table != null) {
        boolean hasMoreElements = !table.isEmpty();
        while (hasMoreElements) {
            list.add(table.getString(xpath));
            if (table.isLastRow()) {
                hasMoreElements = false;
            } else {
                table.nextRow();
            }
        }
    }
    if (list.isEmpty()) {
        variableValue = null;
    } else if (list.size() == 1) {
        variableValue = list.get(0);
    } else {
        variableValue = list;
    }
    return variableValue;
}
Also used : Serializable(java.io.Serializable) JCoTable(com.sap.conn.jco.JCoTable) ArrayList(java.util.ArrayList)

Example 5 with JCoTable

use of com.sap.conn.jco.JCoTable in project JavaClasses by genexuslabs.

the class EnterpriseConnect method setValue.

public void setValue(String parameterName, GXSimpleCollection value, Boolean inOut) {
    JCoTable jTable = function.getTableParameterList().getTable(parameterName);
    Boolean setValues = false;
    try {
        for (int i = 1; i <= value.getItemCount(); i++) {
            IGxJSONAble item = (IGxJSONAble) value.item(i);
            if (item != null) {
                setValues = true;
                JSONObject jObj = (JSONObject) item.GetJSONObject();
                jTable.appendRow();
                jTable.lastRow();
                Iterator<?> keys = jObj.keys();
                while (keys.hasNext()) {
                    String key = (String) keys.next();
                    int jcoType = jTable.getRecordMetaData().getType(key);
                    if (jObj.get(key) instanceof String) {
                        jTable.setValue(key, jObj.getString(key));
                    } else if (jcoType == JCoMetaData.TYPE_NUM || jcoType == JCoMetaData.TYPE_INT) {
                        jTable.setValue(key, jObj.getLong(key));
                    } else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) {
                        jTable.setValue(key, jObj.getDouble(key));
                    } else if (jcoType == JCoMetaData.TYPE_DATE) {
                        jTable.setValue(key, jObj.getString(key));
                    } else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 || jcoType == JCoMetaData.TYPE_BYTE) {
                        jTable.setValue(key, jObj.getInt(key));
                    } else {
                        System.out.println(key + " Invalid Type " + Integer.toString(jcoType));
                    }
                }
            }
        }
    } catch (JSONException ex) {
        throw new RuntimeException(ex.toString());
    }
    if (setValues) {
        function.getTableParameterList().setActive(parameterName, true);
    } else {
        function.getTableParameterList().setActive(parameterName, inOut);
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) JSONObject(json.org.json.JSONObject) JCoTable(com.sap.conn.jco.JCoTable) JSONException(json.org.json.JSONException)

Aggregations

JCoTable (com.sap.conn.jco.JCoTable)7 ArrayList (java.util.ArrayList)5 JCoException (com.sap.conn.jco.JCoException)3 JCoFunction (com.sap.conn.jco.JCoFunction)3 JsonFormParameter (io.clownfish.clownfish.beans.JsonFormParameter)3 CfSitesaprfc (io.clownfish.clownfish.dbentities.CfSitesaprfc)3 RfcFunctionParam (io.clownfish.clownfish.sap.models.RfcFunctionParam)3 RpyTableRead (io.clownfish.clownfish.sap.models.RpyTableRead)3 Serializable (java.io.Serializable)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ConversionException (com.sap.conn.jco.ConversionException)2 SAPConnection (de.destrukt.sapconnection.SAPConnection)2 RFC_GET_FUNCTION_INTERFACE (io.clownfish.clownfish.sap.RFC_GET_FUNCTION_INTERFACE)2 RFC_READ_TABLE (io.clownfish.clownfish.sap.RFC_READ_TABLE)2 RPY_TABLE_READ (io.clownfish.clownfish.sap.RPY_TABLE_READ)2 SAPDATATYPE (io.clownfish.clownfish.sap.SAPDATATYPE)2 ClownfishUtil (io.clownfish.clownfish.utils.ClownfishUtil)2