use of io.clownfish.clownfish.dbentities.CfSitesaprfc in project Clownfish by rawdog71.
the class CfSitesaprfcDAOImpl method findByRfcfunction.
@Override
public List<CfSitesaprfc> findByRfcfunction(String rfcfunction) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfSitesaprfc.findByRfcfunction");
query.setParameter("rfcfunction", rfcfunction);
List<CfSitesaprfc> cfsitesaprfclist = query.getResultList();
return cfsitesaprfclist;
}
use of io.clownfish.clownfish.dbentities.CfSitesaprfc in project Clownfish by rawdog71.
the class CfSitesaprfcDAOImpl method findBySiteref.
@Override
public List<CfSitesaprfc> findBySiteref(long siteref) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfSitesaprfc.findBySiteref");
query.setParameter("siteref", siteref);
List<CfSitesaprfc> cfsitesaprfclist = query.getResultList();
return cfsitesaprfclist;
}
use of io.clownfish.clownfish.dbentities.CfSitesaprfc in project Clownfish by rawdog71.
the class CfSitesaprfcDAOImpl method findAll.
@Override
public List<CfSitesaprfc> findAll() {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfSitesaprfc.findAll");
List<CfSitesaprfc> cfsitesaprfclist = query.getResultList();
return cfsitesaprfclist;
}
use of io.clownfish.clownfish.dbentities.CfSitesaprfc in project Clownfish by rawdog71.
the class QuartzJob method callJob.
private void callJob(long siteref) {
boolean canExecute = false;
// 1 = Staging mode (fetch sourcecode from commited repository) <= default
modus = STAGING;
// read all System Properties of the property table
propertymap = propertylist.fillPropertyMap();
// clownfishutil = new ClownfishUtil();
String sapSupportProp = propertymap.get("sap_support");
if (sapSupportProp.compareToIgnoreCase("true") == 0) {
sapSupport = true;
}
if (sapSupport) {
sapc = new SAPConnection(SAPCONNECTION, "Clownfish5");
rpytableread = new RPY_TABLE_READ(sapc);
}
// Freemarker Template
freemarker.template.Template fmTemplate = null;
Map fmRoot = null;
// Velocity Template
org.apache.velocity.VelocityContext velContext = null;
org.apache.velocity.Template velTemplate = null;
// fetch site by name or aliasname
CfSite cfsite;
cfsite = cfsiteService.findById(siteref);
CfTemplate cftemplate = cftemplateService.findById(cfsite.getTemplateref().longValue());
// fetch the dependend template
switch(cftemplate.getScriptlanguage()) {
case 0:
try {
// Freemarker Template
fmRoot = new LinkedHashMap();
freemarkerCfg = new freemarker.template.Configuration();
freemarkerCfg.setDefaultEncoding("UTF-8");
freemarkerCfg.setTemplateLoader(freemarkerTemplateloader);
freemarkerCfg.setLocalizedLookup(false);
freemarkerCfg.setLocale(Locale.GERMANY);
fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());
canExecute = true;
} catch (MalformedTemplateNameException ex) {
LOGGER.error(ex.getMessage());
} catch (ParseException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
break;
case 1:
try {
// Velocity Template
velContext = new org.apache.velocity.VelocityContext();
velTemplate = new org.apache.velocity.Template();
org.apache.velocity.runtime.RuntimeServices runtimeServices = org.apache.velocity.runtime.RuntimeSingleton.getRuntimeServices();
String templateContent;
long currentTemplateVersion;
try {
currentTemplateVersion = cftemplateversionService.findMaxVersion(cftemplate.getId());
} catch (NullPointerException ex) {
currentTemplateVersion = 0;
}
templateContent = templateUtil.getVersion(cftemplate.getId(), currentTemplateVersion);
templateContent = templateUtil.fetchIncludes(templateContent, modus);
StringReader reader = new StringReader(templateContent);
velTemplate.setRuntimeServices(runtimeServices);
velTemplate.setData(runtimeServices.parse(reader, velTemplate));
velTemplate.initDocument();
canExecute = true;
} catch (org.apache.velocity.runtime.parser.ParseException ex) {
LOGGER.error(ex.getMessage());
}
break;
default:
canExecute = false;
break;
}
if (canExecute) {
// fetch the dependend datasources
sitedatasourcelist = new ArrayList<>();
sitedatasourcelist.addAll(cfsitedatasourceService.findBySiteref(cfsite.getId()));
// Instantiate Template Beans
EmailTemplateBean emailbean = new EmailTemplateBean();
emailbean.init(propertymap, mailUtil, propertyUtil);
if (sapSupport) {
List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
sapbean = new SAPTemplateBean();
sapbean.init(sapc, sitesaprfclist, rpytableread, null);
}
NetworkTemplateBean networkbean = new NetworkTemplateBean();
DatabaseTemplateBean databasebean = new DatabaseTemplateBean();
databasebean.initjob(sitedatasourcelist, cfdatasourceService);
ImportTemplateBean importBean = new ImportTemplateBean();
importBean.initjob(sitedatasourcelist, cfdatasourceService);
WebServiceTemplateBean webServiceBean = new WebServiceTemplateBean();
PDFTemplateBean pdfBean = new PDFTemplateBean();
pdfBean.initjob(pdfUtil);
// write the output
Writer out = new StringWriter();
if (0 == cftemplate.getScriptlanguage()) {
// Freemarker template
if (null != fmRoot) {
fmRoot.put("emailBean", emailbean);
if (sapSupport) {
List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
sapbean = new SAPTemplateBean();
sapbean.init(sapc, sitesaprfclist, rpytableread, null);
fmRoot.put("sapBean", sapbean);
}
fmRoot.put("databaseBean", databasebean);
fmRoot.put("networkBean", networkbean);
fmRoot.put("importBean", importBean);
fmRoot.put("pdfBean", pdfBean);
fmRoot.put("webserviceBean", webServiceBean);
fmRoot.put("property", propertymap);
for (Class tpbc : beanUtil.getLoadabletemplatebeans()) {
Constructor<?> ctor;
try {
ctor = tpbc.getConstructor();
Object object = ctor.newInstance(new Object[] {});
fmRoot.put(tpbc.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
}
try {
if (null != fmTemplate) {
freemarker.core.Environment env = fmTemplate.createProcessingEnvironment(fmRoot, out);
env.process();
}
} catch (freemarker.template.TemplateException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
} else {
// Velocity template
if (null != velContext) {
velContext.put("emailBean", emailbean);
if (sapSupport) {
List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
sapbean = new SAPTemplateBean();
velContext.put("sapBean", sapbean);
}
velContext.put("databaseBean", databasebean);
velContext.put("networkBean", networkbean);
velContext.put("importBean", importBean);
velContext.put("webserviceBean", webServiceBean);
velContext.put("pdfBean", pdfBean);
for (Class tpbc : beanUtil.getLoadabletemplatebeans()) {
Constructor<?> ctor;
try {
ctor = tpbc.getConstructor();
Object object = ctor.newInstance(new Object[] {});
velContext.put(tpbc.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
}
velContext.put("property", propertymap);
if (null != velTemplate) {
velTemplate.merge(velContext, out);
}
}
}
LOGGER.info(out.toString());
} else {
LOGGER.info("CANNOT EXECUTE HTML TEMPLATE");
}
}
use of io.clownfish.clownfish.dbentities.CfSitesaprfc 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;
}
Aggregations