Search in sources :

Example 1 with ConversionException

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

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