use of io.clownfish.clownfish.sap.RPY_TABLE_READ 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.sap.RPY_TABLE_READ in project Clownfish by rawdog71.
the class Clownfish method init.
/**
* Call of the "init" site
* Init is called at the beginning of the Clownfish startup and after changing system properties
* Checks the bootstrap flag of the application.properties and calls a bootstrap routine
* Initializes several variables and starts Quartz job triggers
*/
@PostConstruct
public void init() {
LOGGER.info("INIT CLOWNFISH START");
servicestatus.setMessage("Clownfish is initializing");
servicestatus.setOnline(false);
if (null == authtokenlist) {
authtokenlist = new AuthTokenList();
}
// read all System Properties of the property table
if (null == propertyUtil) {
propertyUtil = new PropertyUtil(propertylist);
}
if (null == cfclassLoader) {
cfclassLoader = new CfClassLoader();
}
if (null == cfclassCompiler) {
cfclassCompiler = new CfClassCompiler();
cfclassCompiler.setClownfish(this);
cfclassCompiler.init(cfclassLoader, propertyUtil, cfjavaService);
}
libloaderpath = propertyUtil.getPropertyValue("folder_libs");
if (null == beanUtil)
beanUtil = new BeanUtil();
if ((!libloaderpath.isBlank()) && (null != libloaderpath))
beanUtil.init(libloaderpath);
mavenpath = propertyUtil.getPropertyValue("folder_maven");
if ((!mavenpath.isBlank()) && (null != mavenpath)) {
if (classpathUtil == null) {
classpathUtil = new ClassPathUtil();
classpathUtil.init(cfclassLoader);
}
classpathUtil.addPath(mavenpath);
}
if (null == mavenlist) {
mavenlist = new MavenList();
mavenlist.setClasspathUtil(classpathUtil);
}
Thread compileThread = new Thread(cfclassCompiler);
compileThread.start();
if (1 == bootstrap) {
bootstrap = 0;
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("BOOTSTRAPPING II");
System.out.println(ansi().reset());
Properties props = new Properties();
String propsfile = "application.properties";
InputStream is = new FileInputStream(propsfile);
if (null != is) {
props.load(is);
props.setProperty("bootstrap", String.valueOf(bootstrap));
File f = new File("application.properties");
bootstrap();
OutputStream out = new FileOutputStream(f);
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(props, out, "Application properties");
} else {
LOGGER.error("application.properties file not found");
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
/* Hazelcast test */
/*
if (null == hazelConfig) {
hazelConfig = new Config();
}
if (null == hcInstance) {
hcInstance = Hazelcast.newHazelcastInstance(hazelConfig);
}
*/
Package p = FacesContext.class.getPackage();
if (null == clownfishutil) {
clownfishutil = new ClownfishUtil();
}
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = null;
if ((new File("pom.xml")).exists()) {
try {
model = reader.read(new FileReader("pom.xml"));
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException | XmlPullParserException ex) {
LOGGER.error(ex.getMessage());
}
}
if (null != model) {
clownfishutil.setVersion(model.getVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
} else {
clownfishutil.setVersion(getClass().getPackage().getImplementationVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
}
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("INIT CLOWNFISH CMS Version " + clownfishutil.getVersion() + " on Tomcat " + clownfishutil.getVersionTomcat() + " with Mojarra " + clownfishutil.getVersionMojarra());
System.out.println(ansi().fg(RED));
System.out.println(" ... ");
System.out.println(" &@@@@@@@ ");
System.out.println(" .&&%%%@%@@@@ ");
System.out.println(" %%%%%%%%&%%@ ");
System.out.println(" .%%%%%%%%#%%& ");
System.out.println(" /%%%%%%%%%##% &&@@. ");
System.out.println(" .,*//#############% %#%#%@@ ");
System.out.println(" #((############### ###%#%%&@ ");
System.out.println(" // #((((/(/(((((((/ (###(###&% ");
System.out.println(" *((//((#/ #((((#(((((((# (((##%##@ ");
System.out.println(" /(((((#(////# .((((((((((((* *((((###% ");
System.out.println(" /(((((#((###### #(((((##((@@@@& ((((((## ");
System.out.println(" (((((((####@@&#(% #((((####((((&@/ #(((((((* (&@@&# ");
System.out.println(" /(((((((#######(((& *((((##(((((((#@/ #(((((((/ &&%%%%&@@@, ");
System.out.println(" /((((((((((((((#((((& (#((#(##((##((@@ #(#####(* *########%%&@@@.");
System.out.println(" /%#(((((((((((((/((((. ###########(((#@* ((#####(. /#########%%%@@@@");
System.out.println(" ,(((((((((((((((((((/ ###########((((@, ((####### ###########%%%@@@");
System.out.println(" .(((((((((((((/((((* (#########((((#@ ((######% .##########%%%&@@@");
System.out.println(" ,/(((((((((((((& #(#########((((@/ .#((###(((( #########%%%%&@@@");
System.out.println(" /((((((##(& %(((((######(((&/ .#(((((((((. *########%%%&&@@@");
System.out.println(" ,//(#@ /(#(####(((##(((&. (((((((((/ /######%%%&&@@@@");
System.out.println(" ./* .#(########((#((*/. *#(((((((###. /%##%%%%@@@@@@ ");
System.out.println(" /######((#######( ./#######(###(#@ .&@@@@@@@% ");
System.out.println(" /#######%%#(((#((((@. /@%#####(##((@# ");
System.out.println(" /####%%#@& *#(((//(/(%@ *@@@@%#%&@@ ");
System.out.println(" %#%&&@&* *((((///(@@& .##/* ");
System.out.println(" ,,***, *((/(#@@@@@, ");
System.out.println(" *@@@@@@@@% ");
System.out.println(ansi().reset());
// Check Consistence
if (checkConsistency > 0) {
consistencyUtil.checkConsistency();
}
// Generate Hibernate DOM Mapping
if (null == hibernateInitializer) {
hibernateInitializer = new HibernateInit(servicestatus, cfclassService, cfattributService, cfclasscontentService, cfattributcontentService, cflistcontentService, cfclasscontentkeywordService, cfkeywordService, dburl);
hibernateUtil.init(hibernateInitializer);
hibernateUtil.setHibernateInit(hibernateInit);
Thread hibernateThread = new Thread(hibernateUtil);
hibernateThread.start();
/*
hibernateUtil.generateTablesDatamodel(hibernateInit);
// generate Relation Tables
hibernateUtil.generateRelationsDatamodel(hibernateInit);
*/
}
propertylist.setClownfish(this);
if (null == defaultUtil) {
defaultUtil = new DefaultUtil();
}
if (mailUtil == null)
mailUtil = new MailUtil(propertyUtil);
if (pdfUtil == null)
pdfUtil = new PDFUtil(cftemplateService, cftemplateversionService, cfsitedatasourceService, cfdatasourceService, cfsiteService, propertyUtil, templateUtil);
// Set default values
// 1 = Staging mode (fetch sourcecode from commited repository) <= default
modus = STAGING;
// 0 = Development mode (fetch sourcecode from database)
defaultUtil.setCharacterEncoding("UTF-8").setContentType("text/html").setLocale(new Locale("de"));
sapSupport = propertyUtil.getPropertyBoolean("sap_support", sapSupport);
if (sapSupport) {
if (null == sapc) {
sapc = new SAPConnection(SAPCONNECTION, "Clownfish1");
rpytableread = new RPY_TABLE_READ(sapc);
}
}
// Override default values with system properties
String systemContentType = propertyUtil.getPropertyValue("response_contenttype");
String systemCharacterEncoding = propertyUtil.getPropertyValue("response_characterencoding");
String systemLocale = propertyUtil.getPropertyValue("response_locale");
if (!systemCharacterEncoding.isEmpty()) {
defaultUtil.setCharacterEncoding(systemCharacterEncoding);
}
if (!systemContentType.isEmpty()) {
defaultUtil.setContentType(systemContentType);
}
if (!systemLocale.isEmpty()) {
defaultUtil.setLocale(new Locale(systemLocale));
}
if (null == gzipswitch) {
gzipswitch = new GzipSwitch();
}
if (null == markdownUtil) {
markdownUtil = new MarkdownUtil(propertylist);
markdownUtil.initOptions();
} else {
markdownUtil.initOptions();
}
if ((null != folderUtil.getIndex_folder()) && (!folderUtil.getIndex_folder().isEmpty())) {
// Call a parallel thread to index the content in Lucene
if (null == contentIndexer) {
contentIndexer = new ContentIndexer(cfattributcontentService, indexService);
}
Thread contentindexer_thread = new Thread(contentIndexer);
contentindexer_thread.start();
LOGGER.info("CONTENTINDEXER RUN");
if (null == assetIndexer) {
assetIndexer = new AssetIndexer(cfassetService, indexService, propertylist);
}
Thread assetindexer_thread = new Thread(assetIndexer);
assetindexer_thread.start();
LOGGER.info("ASSETINDEXER RUN");
indexService.getWriter().commit();
}
// Init Site Metadata Map
if (null == metainfomap) {
// hzMetainfomap = hcInstance.getMap("metainfos");
metainfomap = new HashMap();
}
metainfomap.put("version", clownfishutil.getVersion());
metainfomap.put("versionMojarra", clownfishutil.getVersionMojarra());
metainfomap.put("versionTomcat", clownfishutil.getVersionTomcat());
// Init Lucene Search Map
if (null == searchcontentmap) {
searchcontentmap = new HashMap<>();
}
if (null == searchassetmap) {
searchassetmap = new HashMap<>();
}
if (null == searchassetmetadatamap) {
searchassetmetadatamap = new HashMap<>();
}
if (null == searchclasscontentmap) {
searchclasscontentmap = new HashMap<>();
}
if (null == searchmetadata) {
searchmetadata = new HashMap<>();
}
searchlimit = propertyUtil.getPropertyInt("lucene_searchlimit", LuceneConstants.MAX_SEARCH);
jobSupport = propertyUtil.getPropertyBoolean("job_support", jobSupport);
if (jobSupport) {
scheduler.clear();
// Fetch the Quartz jobs
quartzlist.init();
quartzlist.setClownfish(this);
List<CfQuartz> joblist = quartzlist.getQuartzlist();
joblist.stream().forEach((quartz) -> {
try {
if (quartz.isActive()) {
JobDetail job = newJob(quartz.getName());
scheduler.scheduleJob(job, trigger(job, quartz.getSchedule()));
System.out.println(ansi().fg(GREEN));
System.out.println("JOB SCHEDULE: " + quartz.getName());
System.out.println(ansi().reset());
}
} catch (SchedulerException ex) {
LOGGER.error(ex.getMessage());
}
});
}
AnsiConsole.systemUninstall();
} catch (SchedulerException | IOException ex) {
LOGGER.error(ex.getMessage());
}
folderUtil.init();
servicestatus.setMessage("Clownfish is online");
servicestatus.setOnline(true);
LOGGER.info("INIT CLOWNFISH END");
}
Aggregations