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;
}
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;
}
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;
}
}
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;
}
}
Aggregations