Search in sources :

Example 1 with RfcFunctionParam

use of io.clownfish.clownfish.sap.models.RfcFunctionParam 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 RfcFunctionParam

use of io.clownfish.clownfish.sap.models.RfcFunctionParam in project Clownfish by rawdog71.

the class SAPTemplateBean method execute.

public Map execute(String rfcFunction) {
    JCoTable functions_table;
    HashMap<String, HashMap> sapexport = new HashMap<>();
    HashMap<String, List> saprfcfunctionparamMap = new HashMap<>();
    List<RfcFunctionParam> rfcfunctionparamlist = new ArrayList<>();
    rfcfunctionparamlist.addAll(rfc_get_function_interface.getRfcFunctionsParamList(rfcFunction));
    saprfcfunctionparamMap.put(rfcFunction, rfcfunctionparamlist);
    try {
        HashMap<String, Object> sapvalues = new HashMap<>();
        List<RfcFunctionParam> paramlist = saprfcfunctionparamMap.get(rfcFunction);
        // Setze die Import Parameter des SAP RFC mit den Werten aus den POST Parametern
        JCoFunction function;
        if (jcofunctiontable.containsKey(rfcFunction)) {
            function = jcofunctiontable.get(rfcFunction);
        } else {
            function = sapc.getDestination().getRepository().getFunction(rfcFunction);
            jcofunctiontable.put(rfcFunction, function);
        }
        try {
            if (null != function.getTableParameterList()) {
                function.getTableParameterList().clear();
            }
            if (null != function.getChangingParameterList()) {
                function.getChangingParameterList().clear();
            }
        } catch (Exception ex) {
            LOGGER.error(ex.getMessage());
        }
        for (RfcFunctionParam rfcfunctionparam : paramlist) {
            if (rfcfunctionparam.getParamclass().compareToIgnoreCase("I") == 0) {
                if (null != postmap) {
                    postmap.stream().filter((jfp) -> (jfp.getName().compareToIgnoreCase(rfcfunctionparam.getParameter()) == 0)).forEach((jfp) -> {
                        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 paramclass = rfcfunctionparam.getParamclass().toLowerCase();
            if (paramclass.compareToIgnoreCase("i") == 0) {
                continue;
            }
            String tablename = rfcfunctionparam.getTabname();
            String paramname = rfcfunctionparam.getParameter();
            String exid = rfcfunctionparam.getExid();
            ArrayList<HashMap> tablevalues = new ArrayList<>();
            List<RpyTableRead> rpytablereadlist = null;
            switch(paramclass) {
                case "e":
                    if (exid.compareToIgnoreCase("h") == 0) {
                        String param = new RFC_READ_TABLE(sapc).getTableStructureName("DD40L", "TYPENAME = '" + tablename + "'", 3);
                        functions_table = function.getExportParameterList().getTable(paramname.trim());
                        if (!functions_table.isEmpty()) {
                            rpytablereadlist = getRpytablereadlist(param.trim());
                            setTableValues(functions_table, rpytablereadlist, tablevalues);
                            saptables.put(paramname, tablevalues);
                        }
                    } else {
                        sapvalues.put(rfcfunctionparam.getParameter(), function.getExportParameterList().getString(rfcfunctionparam.getParameter()));
                    }
                    break;
                case "t":
                    functions_table = function.getTableParameterList().getTable(paramname);
                    if (!functions_table.isEmpty()) {
                        rpytablereadlist = getRpytablereadlist(tablename);
                        setTableValues(functions_table, rpytablereadlist, tablevalues);
                        saptables.put(paramname, tablevalues);
                    }
                    setTableValues(functions_table, rpytablereadlist, tablevalues);
                    saptables.put(paramname, tablevalues);
                    break;
                case "c":
                    String param = new RFC_READ_TABLE(sapc).getTableStructureName("DD40L", "TYPENAME = '" + tablename + "'", 3);
                    functions_table = function.getChangingParameterList().getTable(paramname);
                    // rpytablereadlist = rpytableread.getRpyTableReadList(param);
                    if (!functions_table.isEmpty()) {
                        rpytablereadlist = getRpytablereadlist(param);
                        setTableValues(functions_table, rpytablereadlist, tablevalues);
                        saptables.put(paramname, tablevalues);
                    }
                    setTableValues(functions_table, rpytablereadlist, tablevalues);
                    saptables.put(paramname, tablevalues);
                    break;
            }
        }
        sapvalues.put("table", saptables);
        sapexport.put(rfcFunction, sapvalues);
    } catch (JCoException ex) {
        LOGGER.error(ex.getMessage());
    }
    contentmap.put("sap", sapexport);
    return contentmap;
}
Also used : Setter(lombok.Setter) SAPDATATYPE(io.clownfish.clownfish.sap.SAPDATATYPE) Getter(lombok.Getter) JCoFunction(com.sap.conn.jco.JCoFunction) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) Map(java.util.Map) SAPConnection(de.destrukt.sapconnection.SAPConnection) ConversionException(com.sap.conn.jco.ConversionException) RpyTableRead(io.clownfish.clownfish.sap.models.RpyTableRead) Logger(org.slf4j.Logger) JCoException(com.sap.conn.jco.JCoException) RFC_READ_TABLE(io.clownfish.clownfish.sap.RFC_READ_TABLE) Serializable(java.io.Serializable) List(java.util.List) Component(org.springframework.stereotype.Component) JCoTable(com.sap.conn.jco.JCoTable) RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) ClownfishUtil(io.clownfish.clownfish.utils.ClownfishUtil) JsonFormParameter(io.clownfish.clownfish.beans.JsonFormParameter) RFC_GET_FUNCTION_INTERFACE(io.clownfish.clownfish.sap.RFC_GET_FUNCTION_INTERFACE) CfSitesaprfc(io.clownfish.clownfish.dbentities.CfSitesaprfc) RPY_TABLE_READ(io.clownfish.clownfish.sap.RPY_TABLE_READ) JCoFunction(com.sap.conn.jco.JCoFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConversionException(com.sap.conn.jco.ConversionException) JCoException(com.sap.conn.jco.JCoException) RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) RFC_READ_TABLE(io.clownfish.clownfish.sap.RFC_READ_TABLE) JCoTable(com.sap.conn.jco.JCoTable) JCoException(com.sap.conn.jco.JCoException) ArrayList(java.util.ArrayList) List(java.util.List) RpyTableRead(io.clownfish.clownfish.sap.models.RpyTableRead)

Example 3 with RfcFunctionParam

use of io.clownfish.clownfish.sap.models.RfcFunctionParam in project Clownfish by rawdog71.

the class SAPTemplateBean method executeAsync.

public Map executeAsync(String rfcFunction, Map parametermap) {
    try {
        // LOGGER.info("START SAP execute");
        JCoTable functions_table;
        HashMap<String, HashMap> sapexport = new HashMap<>();
        HashMap<String, List> saprfcfunctionparamMap = new HashMap<>();
        List<RfcFunctionParam> rfcfunctionparamlist = new ArrayList<>();
        rfcfunctionparamlist.addAll(rfc_get_function_interface.getRfcFunctionsParamList(rfcFunction));
        saprfcfunctionparamMap.put(rfcFunction, rfcfunctionparamlist);
        List<JsonFormParameter> postmap_async = ClownfishUtil.getJsonFormParameterList(parametermap);
        HashMap<String, Object> sapvalues = new HashMap<>();
        List<RfcFunctionParam> paramlist = saprfcfunctionparamMap.get(rfcFunction);
        JCoFunction function;
        try {
            // Setze die Import Parameter des SAP RFC mit den Werten aus den POST Parametern
            if (jcofunctiontable.containsKey(rfcFunction)) {
                function = jcofunctiontable.get(rfcFunction);
            } else {
                function = sapc.getDestination().getRepository().getFunction(rfcFunction);
                jcofunctiontable.put(rfcFunction, function);
            }
            try {
                if (null != function.getTableParameterList()) {
                    function.getTableParameterList().clear();
                }
                if (null != function.getChangingParameterList()) {
                    function.getChangingParameterList().clear();
                }
            } catch (Exception ex) {
                LOGGER.error(ex.getMessage());
            }
            for (RfcFunctionParam rfcfunctionparam : paramlist) {
                if (rfcfunctionparam.getParamclass().compareToIgnoreCase("I") == 0) {
                    if (null != postmap_async) {
                        postmap_async.stream().filter((jfp) -> (jfp.getName().compareToIgnoreCase(rfcfunctionparam.getParameter()) == 0)).forEach((jfp) -> {
                            function.getImportParameterList().setValue(rfcfunctionparam.getParameter(), jfp.getValue());
                        });
                    }
                }
            }
            // SAP RFC ausführen
            // LOGGER.info("START SAP RFC execute");
            function.execute(sapc.getDestination());
            // LOGGER.info("STOP SAP RFC execute");
            HashMap<String, ArrayList> saptables = new HashMap<>();
            for (RfcFunctionParam rfcfunctionparam : paramlist) {
                String paramclass = rfcfunctionparam.getParamclass().toLowerCase();
                if (paramclass.compareToIgnoreCase("i") == 0) {
                    continue;
                }
                String tablename = rfcfunctionparam.getTabname();
                String paramname = rfcfunctionparam.getParameter();
                String exid = rfcfunctionparam.getExid();
                ArrayList<HashMap> tablevalues = new ArrayList<>();
                tablevalues.clear();
                List<RpyTableRead> rpytablereadlist;
                switch(paramclass) {
                    case "e":
                        if (exid.compareToIgnoreCase("h") == 0) {
                            String param = new RFC_READ_TABLE(sapc).getTableStructureName("DD40L", "TYPENAME = '" + tablename + "'", 3);
                            functions_table = function.getExportParameterList().getTable(paramname.trim());
                            if (!functions_table.isEmpty()) {
                                rpytablereadlist = getRpytablereadlist(param.trim());
                                setTableValues(functions_table, rpytablereadlist, tablevalues);
                                saptables.put(paramname, tablevalues);
                            }
                        } else {
                            sapvalues.put(rfcfunctionparam.getParameter(), function.getExportParameterList().getString(rfcfunctionparam.getParameter()));
                        }
                        break;
                    case "t":
                        functions_table = function.getTableParameterList().getTable(paramname);
                        if (!functions_table.isEmpty()) {
                            rpytablereadlist = getRpytablereadlist(tablename);
                            setTableValues(functions_table, rpytablereadlist, tablevalues);
                            saptables.put(paramname, tablevalues);
                        }
                        break;
                    case "c":
                        String param = new RFC_READ_TABLE(sapc).getTableStructureName("DD40L", "TYPENAME = '" + tablename + "'", 3);
                        functions_table = function.getChangingParameterList().getTable(paramname);
                        try {
                            if (!functions_table.isEmpty()) {
                                rpytablereadlist = getRpytablereadlist(param.trim());
                                // rpytablereadlist = rpytableread.getRpyTableReadList(param);
                                setTableValues(functions_table, rpytablereadlist, tablevalues);
                                saptables.put(paramname, tablevalues);
                            }
                        } catch (ConversionException ex) {
                            LOGGER.error(ex.getMessage());
                        }
                        break;
                }
            }
            sapvalues.put("table", saptables);
            sapexport.put(rfcFunction, sapvalues);
        } catch (JCoException ex) {
            LOGGER.error(ex.getMessage());
        }
        contentmap.put("sap", sapexport);
        // LOGGER.info("STOP SAP execute");
        return contentmap;
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage());
        return contentmap;
    }
}
Also used : Setter(lombok.Setter) SAPDATATYPE(io.clownfish.clownfish.sap.SAPDATATYPE) Getter(lombok.Getter) JCoFunction(com.sap.conn.jco.JCoFunction) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) Map(java.util.Map) SAPConnection(de.destrukt.sapconnection.SAPConnection) ConversionException(com.sap.conn.jco.ConversionException) RpyTableRead(io.clownfish.clownfish.sap.models.RpyTableRead) Logger(org.slf4j.Logger) JCoException(com.sap.conn.jco.JCoException) RFC_READ_TABLE(io.clownfish.clownfish.sap.RFC_READ_TABLE) Serializable(java.io.Serializable) List(java.util.List) Component(org.springframework.stereotype.Component) JCoTable(com.sap.conn.jco.JCoTable) RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) ClownfishUtil(io.clownfish.clownfish.utils.ClownfishUtil) JsonFormParameter(io.clownfish.clownfish.beans.JsonFormParameter) RFC_GET_FUNCTION_INTERFACE(io.clownfish.clownfish.sap.RFC_GET_FUNCTION_INTERFACE) CfSitesaprfc(io.clownfish.clownfish.dbentities.CfSitesaprfc) RPY_TABLE_READ(io.clownfish.clownfish.sap.RPY_TABLE_READ) ConversionException(com.sap.conn.jco.ConversionException) JCoFunction(com.sap.conn.jco.JCoFunction) HashMap(java.util.HashMap) JsonFormParameter(io.clownfish.clownfish.beans.JsonFormParameter) ArrayList(java.util.ArrayList) ConversionException(com.sap.conn.jco.ConversionException) JCoException(com.sap.conn.jco.JCoException) RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) RFC_READ_TABLE(io.clownfish.clownfish.sap.RFC_READ_TABLE) JCoTable(com.sap.conn.jco.JCoTable) JCoException(com.sap.conn.jco.JCoException) ArrayList(java.util.ArrayList) List(java.util.List) RpyTableRead(io.clownfish.clownfish.sap.models.RpyTableRead)

Example 4 with RfcFunctionParam

use of io.clownfish.clownfish.sap.models.RfcFunctionParam in project Clownfish by rawdog71.

the class RFC_GET_FUNCTION_INTERFACE method getRfcFunctionsParamList.

public List<RfcFunctionParam> getRfcFunctionsParamList(String funcname) {
    try {
        sapc.getDestination().getRepository().clear();
        JCoFunction function = sapc.getDestination().getRepository().getFunction("RFC_GET_FUNCTION_INTERFACE");
        function.getImportParameterList().setValue("FUNCNAME", funcname);
        function.getImportParameterList().setValue("NONE_UNICODE_LENGTH", " ");
        function.getImportParameterList().setValue("LANGUAGE", "DE");
        function.execute(sapc.getDestination());
        functions_table = function.getTableParameterList().getTable("PARAMS");
        List<RfcFunctionParam> functionsList = new ArrayList<>();
        for (int i = 0; i < functions_table.getNumRows(); i++) {
            functions_table.setRow(i);
            RfcFunctionParam rfcfunctionparam = new RfcFunctionParam(functions_table.getString("PARAMCLASS"), functions_table.getString("PARAMETER"), functions_table.getString("TABNAME"), functions_table.getString("FIELDNAME"), functions_table.getString("EXID"), functions_table.getInt("POSITION"), functions_table.getInt("OFFSET"), functions_table.getInt("INTLENGTH"), functions_table.getInt("DECIMALS"), functions_table.getString("DEFAULT"), functions_table.getString("PARAMTEXT"), functions_table.getString("OPTIONAL"));
            functionsList.add(rfcfunctionparam);
        }
        return functionsList;
    } catch (JCoException ex) {
        LOGGER.error(ex.getMessage());
        return null;
    }
}
Also used : RfcFunctionParam(io.clownfish.clownfish.sap.models.RfcFunctionParam) JCoFunction(com.sap.conn.jco.JCoFunction) JCoException(com.sap.conn.jco.JCoException) ArrayList(java.util.ArrayList)

Aggregations

JCoException (com.sap.conn.jco.JCoException)4 JCoFunction (com.sap.conn.jco.JCoFunction)4 RfcFunctionParam (io.clownfish.clownfish.sap.models.RfcFunctionParam)4 ArrayList (java.util.ArrayList)4 JCoTable (com.sap.conn.jco.JCoTable)3 JsonFormParameter (io.clownfish.clownfish.beans.JsonFormParameter)3 CfSitesaprfc (io.clownfish.clownfish.dbentities.CfSitesaprfc)3 RpyTableRead (io.clownfish.clownfish.sap.models.RpyTableRead)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 HashMap (java.util.HashMap)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 Serializable (java.io.Serializable)2 List (java.util.List)2