Search in sources :

Example 6 with JCoTable

use of com.sap.conn.jco.JCoTable 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 7 with JCoTable

use of com.sap.conn.jco.JCoTable 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)

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